我试着写一个汽车类,里面有一个名为"引擎"在里面 我在创建引擎实例时遇到问题(命名为" myengine") *错误代码表示我有未解决的外部 我会很感激任何帮助/评论
**this is the car header**
#include "engine.h"
#ifndef _car_
#define _car_
class car
{
engine myengine; //here is the error
char* brandname="mybrand";
char* model="mymodel";
};
#endif
**this is the engine header**
#ifndef _engine_
#define _engine_
class engine
{
public:
float volume;
float currentfuel;
float maxfuel;
bool activated; //off
engine();
engine(float volume, float currentfuel, float maxfuel, bool activated) { 10, 0, 100, 0; }
~engine();
void setfuel(float fuel);
float getfuel();
float getmaxfuel();
void setmaxfuel(float maxfuel);
float getvolume();
void setvolume(float volume);
void setactivated(bool active);
bool getactivated();
void activate(bool active);
};
#endif
**this is the engine cpp**
#include "engine.h"
#include <iostream>
using namespace std;
void engine::setfuel(float fuel)
{
cout<<"enter fuel amount"<<endl;
cin >> fuel;
if (fuel < 0)
{
cout << "the amount of fuel cannot be less than 0";
}
else fuel = currentfuel;
}