How can i compile the below code without changing the status of int data?
template<typename U>
void Test(U);
template< class T >
class B {
int data;
public:
friend void Test<>( T );
};
template<typename U>
void Test(U u) {
B < int> b1;
b1.data = 7;
}
int main(int argc, char *argv[])
{
char i;
Test(i);
system("PAUSE");
return 0;
}
The above code causes a compiler error, because b1.data
is private in Test
with U = char
.