Reputation: 531
If I have a template class:
template<typename Layout>
class LayoutHandler : Handler {
};
and I want to expose the parameter Layout to the user of the class. Then:
template<typename Layout>
class LayoutHandler : Handler {
public:
typedef Layout Layout; // using the same name
};
VS2012 can compile this code, and give the expected result. (I use std::is_same to check it.) Is this allowed in standard C++03 or C++11?
Upvotes: 13
Views: 1413
Reputation: 1824
It is not allowed in C++11.
A typedef
is a declaration. (see section 7.1.3)
A template
parameter can't be redeclared within its scope (including nested scopes). (see section 14.6.1.6)
Upvotes: 6
Reputation: 1675
No till C+11 you can't use it, it gives you an error.
declaration of ‘typedef Layout LayoutHandler::Layout’ error: shadows template parm ‘class Layout’
Upvotes: 1