正在加载图片...
class at float x, y; 友元函数只能用对象 public 名引用类中的数据。 A (float a, float b x=a;y=b; j 成员函数 float Sumo return x+y;3 friend float Sum(a &a return axa y, 3 友元函数 私有数据 void main(void) {A1(4,5)2(10,20);成员西数的调用,利用对象名调用 cout<<t1 Sum(<<endl; c0ut<sum(t2)≤endl 友元函数的调用,直接调用第一章 VC集成开发 环境 7 class A{ float x,y; public: A(float a, float b){ x=a; y=b;} float Sum(){ return x+y; } friend float Sum(A &a){ return a.x+a.y; } }; void main(void) { A t1(4,5),t2(10,20); cout<<t1.Sum()<<endl; cout<<Sum(t2)<<endl; } 友元函数 成员函数 友元函数的调用,直接调用 成员函数的调用,利用对象名调用 友元函数只能用对象 名引用类中的数据。 私有数据
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有