With C ++ 11 with hard-typed enum s, you can declare an enumeration of class members as follows:
class X { public: enum class E; }; enum class X::E { a, b };
However, when creating an X class template:
template <typename T> class X { public: enum class E; }; template <typename T> enum class X<T>::E { a, b };
gcc 4.7.2 and clang 3.0 both complain about "error:" enum X :: E is the enumeration template [-pedantic] and "error: enumeration cannot be a template, respectively. Section of the standard that I consider relevant (and in fact, this question arose from), is ยง14 of the Templates, the first paragraph of which reads:
The declaration in the template declaration must
- declare or define a function or class or
- define a member function, a member class, an enumeration of elements, or a static data element of a class template or class nested in a class template, or
- define a template element for a class or class template or
- it is an ad alias.
(my emphasis). So is this a compiler error, or am I misinterpreting the expression?
c ++ enums c ++ 11 templates forward-declaration
Taral
source share