//关于友元:可以*取得friend中private成员 //相同class的各object互为友元 #include <iostream> using namespace std; class complex{ public: complex(int r=0,int i=0) :re(r),im(i){ } int func(const complex& friends) { return friends.re+friends.im; } private: int re,im; }; int main() { complex c1(3,4); complex c2; cout<<c2.func(c1)<<endl; return 0; }