#includeclass Fuel;class Engine{int a,b;public:Engine(int xa=1,int xb=2){a=xa;b=xb;};friend class Fuel;int &geta(){return a;}int &getb(){return b;}};class Fuel{Engine e;public:void show();};void Fuel::show(){cout
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/27 08:02:06
![#includeclass Fuel;class Engine{int a,b;public:Engine(int xa=1,int xb=2){a=xa;b=xb;};friend class Fuel;int &geta(){return a;}int &getb(){return b;}};class Fuel{Engine e;public:void show();};void Fuel::show(){cout](/uploads/image/z/9183828-12-8.jpg?t=%23includeclass+Fuel%3Bclass+Engine%7Bint+a%2Cb%3Bpublic%3AEngine%28int+xa%3D1%2Cint+xb%3D2%29%7Ba%3Dxa%3Bb%3Dxb%3B%7D%3Bfriend+class+Fuel%3Bint+%26geta%28%29%7Breturn+a%3B%7Dint+%26getb%28%29%7Breturn+b%3B%7D%7D%3Bclass+Fuel%7BEngine+e%3Bpublic%3Avoid+show%28%29%3B%7D%3Bvoid+Fuel%3A%3Ashow%28%29%7Bcout)
#includeclass Fuel;class Engine{int a,b;public:Engine(int xa=1,int xb=2){a=xa;b=xb;};friend class Fuel;int &geta(){return a;}int &getb(){return b;}};class Fuel{Engine e;public:void show();};void Fuel::show(){cout
#include
class Fuel;
class Engine
{
int a,b;
public:
Engine(int xa=1,int xb=2){a=xa;b=xb;};
friend class Fuel;
int &geta(){return a;}
int &getb(){return b;}
};
class Fuel
{
Engine e;
public:
void show();
};
void Fuel::show()
{cout
#includeclass Fuel;class Engine{int a,b;public:Engine(int xa=1,int xb=2){a=xa;b=xb;};friend class Fuel;int &geta(){return a;}int &getb(){return b;}};class Fuel{Engine e;public:void show();};void Fuel::show(){cout
楼主,把Fuel f(); 改为 Fuel f;就OK了
Fuel f; 调用无参构造函数,当无参构造函数没写时,系统自动默认.
// Fuel(){} //无参构造函数
// Fuel(Engine en){e=en;} //有参构造函数
当你写有参构造函数时,必要写无参构造函数,防止出错!
具体看看代码把:
#include
class Fuel;
class Engine
{
int a,b;
public:
Engine(int xa=1,int xb=2){a=xa;b=xb;};
friend class Fuel;
int &geta(){return a;}
int &getb(){return b;}
};
class Fuel
{
Engine e;
public:
// Fuel(){} //无参构造函数
// Fuel(Engine en){e=en;} //有参构造函数
void show();
};
void Fuel::show()
{cout