两个类 class A { public: ... int Getx(){return X;} friend class B; private: ... }; class B { public: ... private: A a; }; 当创建一个B类的对象时,A类也会创建一个对象吗?但怎么用该对象调用类A中的函数.如创建了B类对象b,怎么通过A的对象a来调用Getx()
class A { public: ... int Getx(){return X;} friend class B; private: ... }; class B { public: int get(A a){return a.Getx();} //or int get(){return a.Getx();} private: A a;//在用友员时不用定义 };