I have a need in my code for two template classes to be composed of a member field of each other. For example, I have two files,
templates.h
template <class T> class B;
template <class T>
class A
{
B<A> a;
// fields and methods dependent on T
};
template <class T>
class B
{
A<B> b;
// fields and methods dependent on T
};
main.cpp
#include "templates.h"
int main()
{
A<int> a;
}
When I compile I receive the output shown in this link
I am using the g++ compiler. When I type g++ --version, I get
g++ (Gentoo 4.7.2 p1.3, pie-0.5.5) 4.7.2
If this is not possible to do in c++, what is an alternative or work around? Or perhaps is this a bug with my compiler?
See Question&Answers more detail:os