【发布时间】:2016-11-29 15:54:52
【问题描述】:
我正在 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;
};
平面.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;
}
我看到有很多关于这个问题的问题,但我没有解决它。 你能帮我吗()? 谢谢
【问题讨论】:
-
请发布确切的错误
-
究竟是什么符号没有找到?
-
您缺少
Actor::Actor()的实现,这是必需的,因为Plane是Actor的子类,您需要在构造Actor之前构造Plane-因为它微不足道;您可以在actor.h中使用Actor::Actor() {},它应该解决
标签: c++ qt qt-creator