#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/12/23 09:56:10
#includeclassFuel;classEngine{inta,b;public:Engine(intxa=1,intxb=2){a=xa;b=xb;};friendclassFuel;int&

#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