I have the following template class and template function which intends to access the class\' private data member:
#include
template
This one compiles on MSVC2013. Basicly adds the forward declarations to class and functions before the friend
template class MyVar ; // class forward declaration
template ; // function forward declarations
void printVar(const MyVar& var);
template
void scanVar(MyVar& var);
template
class MyVar
{
friend void printVar(const MyVar&);
friend void scanVar(MyVar&);
int x;
};
template
void printVar(const MyVar& var)
{
std::cout << var.x << std::endl;
}
template
void scanVar(MyVar& var)
{
std::cin >> var.x;
}
struct Foo {};
int main1(void)
{
MyVar a;
scanVar(a);
printVar(a);
return 0;
}