2第二讲——类及对象.ppt

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 友元成员函数 #include iostream.h class two; //前置声明 class one { int a; public: void fun(two ); //因涉及“前置声明”,故必需将函数实现放在类外!因为此时尚无法使用two 的任何成员。 void get (void ){coutaendl;} }; 关于前置声明: 前置声明的类只是声明,不是定义。是将标识符“挂了个号”,尚没有细节,因此不能使用类的成员,也不能创建对象,但可以声明指向该类类型的指针或引用。 class two { int b; friend void one::fun(two ); //one的成员函数在two中是友元成员函数 public: void put (int i){b=i;coutbendl;} }; void one::fun(twor){a=r.b;coutaendl;} //友元成员函数的函数实现放在类外 void main() { one oa; two ob; ob.

文档评论(0)

1亿VIP精品文档

相关文档