'a' : cannot access private member declared in class 'father'
- C/C++ code
#include<iostream>using namespace std;class father{public: father() { a = 0,b = 0; }private: int a,b;};class Child{public: Child() { c = 1,d = 1; }private: father gc; int c,d; friend void Print(Child & child);};void Print(Child & child){ cout<<child.gc.a<<" "<<child.gc.b<<endl;}int main(void){ Child test; Print(test); return 250;}我今天看书上的解题的时候,碰见了这个问题,错误提示如下
Compiling...
DosTest.cpp
d:\vc 6.0test\dostest\dostest.cpp(36) : error C2248: 'a' : cannot access private member declared in class 'father'
d:\vc 6.0test\dostest\dostest.cpp(12) : see declaration of 'a'
d:\vc 6.0test\dostest\dostest.cpp(36) : error C2248: 'b' : cannot access private member declared in class 'father'
d:\vc 6.0test\dostest\dostest.cpp(12) : see declaration of 'b'
Error executing cl.exe.
DosTest.exe - 2 error(s), 0 warning(s)
求高手解决
[解决办法]