我正在uni做一个练习,每次我试图编译main.cpp时,我都会遇到同样的错误。
执行人H:
class Actor {
public:
Actor();
Actor(double x0, double y0);
void move();
double pos_x();
double pos_y();
static const int ARENA_W = 500;
static const int ARENA_H = 500;
};
Plane.h(actor的子类):
class Plane:Actor
{
public:
Plane();
Plane(double x0, double y0);
void move();
double pos_x();
double pos_y();
//int dx = 5;
static const int W = 50;
static const int H = 20;
private:
double x, y;
};
plane.cpp
#include "plane.h"
#include "actor.h"
Plane::Plane(double x0, double y0)
{
this ->x = x0;
this ->y = y0;
//this -> dx;
}
void Plane::move()
{
x = x + 2.5 ;
}
double Plane::pos_x()
{
return x;
}
double Plane::pos_y()
{
return y;
}
main.cpp
include "plane.h"
include"actor.h"
using namespace std;
int main(int argc, char *argv[])
{
Plane plane1(25.0, 5.0);
plane1.move();
double x = plane1.pos_x();
double y = plane1.pos_y();
cout << x << " , " << y<<endl;
}
我看到这个问题有很多问题,但我没有解决它。你能帮我一下吗?谢谢
您已经在
class Actor {
public: Actor();
};
这意味着您将编写一些代码来定义这个构造。这通常以
如果您试图在没有此实现的情况下构造
现在您已经声明了一个
class Plane : Actor {
};
并且定义了一个非默认构造函数:
Plane::Plane(double, double) {
// does something
}
因为
有点简单的解决方案是在 现在,关于这里的行为--没有一个class Actor {
public:
Actor() {} // replace the ; with {}
Actor(double x0, double y0);
void move();
double pos_x();
double pos_y();
static const int ARENA_W = 500;
static const int ARENA_H = 500;
};