I am trying to declare a function as friend to a class template with a protected member. Below is a minimal example.
template<int N> class myClass{
public:
friend void f(const myClass& c);
protected:
int a;
};
If I now define the function as
template<int N> void f(const myClass<N>& c){
std::cout << c.a;
};
Then it works.
However if I use template specialisation
template<int N> void f(const myClass<N>& c);
template<> void f<1>(const myClass<1>& c){
std::cout << c.a;
};
It does not recognise f
as a friend anymore and complains that a
is a protected member.
Why is that happening? What am I doing wrong?