1 #include <iostream> 2 using namespace std; 3 4 //友元函数的主要作用就是访问私有变量 5 class myclass 6 { 7 public: 8 friend class newclass; 9 private: 10 int x; 11 int y; 12 int z; 13 14 15 }; 16 17 class newclass 18 { 19 private: 20 myclass my; 21 char *password = "calc"; 22 23 public: 24 void outit() 25 { 26 cout << password << my.x << my.y << my.z; 27 } 28 }; 29 30 void main() 31 { 32 33 cin.get(); 34 }