如果我有一个模板类:
template<typename Layout>
class LayoutHandler : Handler {
};
我希望将参数"Layout"暴露给该类的用户,因此:
template<typename Layout>
class LayoutHandler : Handler {
public:
typedef Layout Layout; // using the same name
};
VS2012可以编译此代码并给出预期结果。(我使用std::is_same进行检查。) 这在标准的C++03或C++11中允许吗?
typedef Layout LayoutType;
这样更易读。 - πάντα ῥεῖtypedef
使用相同的名称有什么目的?我不太明白。 - Marson Maotypedef
的目的是使模板参数类型在类外部的代码中可用。 - programmerjake