I have the following code in a .h
file:
class Test1 {
struct A1 {
int x;
};
static const A1 a1;
};
template <class T>
class Test2 {
struct A2 {
int x;
};
static const A2 a2;
};
and I define values for both a1
and a2
in a .cpp
file:
const Test1::A1 Test1::a1 = { 5 };
template<class T>
const Test2<T>::A2 Test2<T>::a2 = { 5 };
The odd thing is that for Test1
everything works, but for Test2
I get the following error in the last line of the .cpp
file:
Error C2061 syntax error: identifier 'A2'
The only difference between Test1
and Test2
is that Test2
has a template. Why is this a problem, and how can I fix it? Also, this works as well:
test.h
struct A3 {
int x;
};
template <class T>
class Test3 {
static const A3 a3;
};
test.cpp
template<class T>
const A3 Test3<T>::a3 = { 5 };
So the problem is with using a struct defined in a templated class, but I can't find out what exactly is the problem.
(I'm compiling with c++14.)