正在加载图片...
const float Pl =3. 1415926 class A float r float h public: A(float a, float br=a; h=b, 1 类B中的任何函数都 float Getroreturnr; 1 float Geth(return h; 1 能使用类A中的所有 friend class B;/定义类B为类A的友元私有成员。 class B i int number; public: B(int n=1) inumber=n; 1 void Show (A &a) cout<P|*ar*ar* a number.<send;}求类A的某个对象ηn的体积 void main(void) Aa1(25,40),a2(10,40); Bb1(2) b1. Show(a1);b1.Show(a2); 直接引用类A的私有成员第一章 VC集成开发 环境 16 const float PI =3.1415926; class A{ float r ; float h; public: A(float a,float b){r=a; h=b;} float Getr(){return r;} float Geth(){return h;} friend class B;//定义类B为类A的友元 }; class B { int number; public: B(int n=1) {number=n;} void Show(A &a) { cout<<PI*a.r*a.r*a.h*number<<endl; }//求类A的某个对象*n的体积 }; void main(void) { A a1(25,40),a2(10,40); B b1(2); b1.Show (a1); b1.Show (a2); } 直接引用类A的私有成员 类B中的任何函数都 能使用类A中的所有 私有成员
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有