In other words, why does this compile fine :
template
class A{
public:
void f();
};
class B{
friend void A::f();
};
tem
Specializing template class
member function without specializing whole template class
is special case when you are allowed to specialize non-template
member function, so maybe GCC
is confused, and I don't know the reasons, but somehow you can't declare friendship to specialized non-template
member of template class
. Temporary solution would be to specialize whole class template
for this to work.
//class template A
template
class A{
public:
void f();
};
//class A
template<>
class A{
public:
void f();
};
Then, define A
:
For class B:
void A::f(){
B* var = new B();
(void)(var);
}
For template class B
:
void A::f(){
B* var = new B();
(void)(var);
}
But I think Clang
is right here, there should be no problems for such friend declaration. It's probably a bug in GCC
.