|
| » 首页 » 电脑_数码 » 编程 » 重写以下的程序,将函数leisure改为友元 |
重写以下的程序,将函数leisure改为友元 |
|
using namespace std; class Car { int size; public: void SetSize(int value) { size = value; } int GetSize() { return size; } }; class Boat { int size; public: void SetSize(int value) { size = value; } int GetSize() { return size; } }; int leisure(int time,Car &aobj,Boat &bobj) { return time * aobj.GetSize() * bobj.GetSize(); } void main() { Car c1; c1.SetSize(2); Boat b1; b1.SetSize(3); cout<<leisure(5,c1,b1)<<endl; } |
![]() |
|
|
在class Boat定义中将int leisure(int time,Car &aobj,Boat &bobj) 的声明改为:friend leisure(int time,Car &aobj,Boat &bobj), 然后在类外进行定义 |
| 《重写以下的程序,将函数leisure改为友元》答案收集时间:2008-06-14 14:31:28 |