In other words, why does this compile fine :
template
class A{
public:
void f();
};
class B{
friend void A::f();
};
tem
An explicit instantiation of B
before it is used in A
resolves this problem. I assume GCC tries an implicit instantiation of B
in the definition of A
. But the definition of A
is not finished and GCC 'looses' the friend declaration. It looks like a compiler problem.
template
class A
{
public:
void f();
};
template // B is now a templated class
class B
{
friend void A::f(); // Friending is done using B templated type
};
template
class B; // <= explicit instantiation, that works
template<>
void A::f()
{
B* var = new B();
}