提问者:小点点

C++错误::-1:错误:在Qt-Creator中找不到体系结构x86_64的符号


我正在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;
}

我看到这个问题有很多问题,但我没有解决它。你能帮我一下吗?谢谢


共1个答案

匿名用户

您已经在中声明了一个类:

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;
};

现在,关于这里的行为--没有一个方法被声明为,因此它们不会在中被重载;它们只是被取代了。这可能会在你的课程后面提到。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|qt-creator|中|找不到|体系结构|x86_64|符号)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?