I have the following template class and template function which intends to access the class\' private data member:
#include
template
Well there is a solution that is both simple and involving separation between declaration & definition of the friend function. In the declaration of the friend function (inside the class) you have to give a different template param from the one the class accepts (and it make sense cause this function is not a member of this class).
template
class MyVar
{
int x;
template
friend void printVar(const MyVar & var);
template
friend void scanVar(MyVar & var);
};
template
void printVar(const MyVar & var) {
}
template
void scanVar(MyVar & var) {
}
No forward declaration needed, as well as there is a separation of declaration & definition.