Does anyone know why the following fails to compile (tested in MSVC2015)?
template<int N> // when this line is removed it compiles successfully
class A {
class B {
public:
class C {
};
};
void func(B b){} // compiles fine
void func(B::C c){} // generates warning C4346 and error C2061
};
It generates the following on the line marked with a comment:
warning C4346: 'A<N>::B::C': dependent name is not a type
error C2061: syntax error: identifier 'C'
Let's google it for you.
The
typename
keyword is required if a dependent name is to be treated as a type.
C++ rule.
14.6 Name resolution
A name used in a template declaration or definition and that is dependent on a template-parameter is assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified by the keyword
typename
.