Two template classes can use each other as template argument, but if I use anything defined in one class scope, it cannot be compiled.
template<class B> struct A {
typedef A *pointer;
};
template<class A> struct B {
//typedef A::pointer APtr;
//using APtr = A::pointer;
//APtr pa;
A::pointer pa;
};
struct AA;
struct BB;
struct AA : public A<BB> {};
struct BB : public B<AA> {};
VS2017 complained:
1>c:\test.cpp(59): warning C4346: 'pointer': dependent name is not a type
1>c:\test.cpp(59): note: prefix with 'typename' to indicate a type
1>c:\test.cpp(60): note: see reference to class template instantiation 'B<A>' being compiled
1>c:\test.cpp(59): error C2061: syntax error: identifier 'pointer'
1>c:\test.cpp(59): error C2238: unexpected token(s) preceding ';'
1>c:\test.cpp(69): warning C4091: '': ignored on left of 'A<BB> *' when no variable is declared
Is it also involved circular dependency? Is there one possible way to fix it?