There is a post explaining that a template parameter can be declared as friend with the following syntax:
template <typename T>
class A {
friend T;
};
but what if in some scenarios A needs a fried and in others does not? Is it possible to make T an optional argument?
Is there a better solution than using some kind of FakeClass as T?
EDIT1: I found another solution:
class B {};
template <typename T>
class A {
friend T;
};
template <>
class A<void> {
};
int main()
{
A<B> a1;
A<void> a2;
return 0;
}
but what if A is a complicated class with 300 lines of code? Is there an alternative solution without template specialization?