template <class T=A>
struct B {
T a;
};
struct A {
B<A> foo(){
B<A> result;
return result;
}
};
How can I avoid having to use a template (mind the default parameter to see its usage).
The problem is that both classes require each other’s definitions. But there’s no “real” circular dependence as the template solution shows.
You can exploit the fact that a forward declaration is sufficient in case you’re returning by value (as is the case with
A::foo):