I don't see why not, so long as the A has been forward declared. Obviously, you couldn't make an actual instance of A inside of A, but you could make a pointer or something like that.
template<typename T, typename U = A<T> >
class A {
A<T> *ex;
};
int main(void){
A<int> a;
};
and I get this:
1 2 3 4 5 6 7 8
teste.cpp:8:35: error: expected type-specifier before 'A'
teste.cpp:8:35: error: expected '>' before 'A'
teste.cpp:10:5: error: template argument 2 is invalid
teste.cpp: In function 'int main()':
teste.cpp:15:7: error: template argument 2 is invalid
teste.cpp:15:10: error: invalid type in declaration before ';' token
teste.cpp:15:10: warning: unused variable 'a'
What are you trying to do exactly?
Forward declaration or not, the problem here is the infinite template recursion.
You cant stop it by specifying a second template argument like this:
1 2 3 4 5 6 7 8 9 10
template<typename T, typename U = A<T, int> >
class A {
A<T> *ex;
};
int main(void){
A<int> a;
};