C++ 错误::-1: 错误:找不到 x86_64 体系结构的符号 - 在 Qt-Creator 中 [英] c++ error: :-1: error: symbol(s) not found for architecture x86_64 - in Qt-Creator

查看:40
本文介绍了C++ 错误::-1: 错误:找不到 x86_64 体系结构的符号 - 在 Qt-Creator 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 uni 做一个练习,每次我尝试编译 main.cpp 时,我总是遇到同样的错误.

actor.h:

class 演员 {上市:演员();演员(双x0,双y0);空移动();双 pos_x();双 pos_y();静态常量 int ARENA_W = 500;静态常量 int ARENA_H = 500;};

plane.h(actor 的子类):

类飞机:演员{上市:飞机();平面(双x0,双y0);空移动();双 pos_x();双 pos_y();//int dx = 5;静态常量 int W = 50;静态常量 int H = 20;私人的:双 x, y;};

平面.cpp

#include "plane.h"#include "actor.h"平面::平面(双x0,双y0){这 -> x = x0;这 -> y = y0;//这个->dx;}空平面::移动(){x = x + 2.5 ;}双平面::pos_x(){返回 x;}双平面::pos_y(){返回 y;}

main.cpp

包括plane.h"包括actor.h"使用命名空间标准;int main(int argc, char *argv[]){平面plane1(25.0, 5.0);平面1.移动();双 x = plane1.pos_x();双 y = plane1.pos_y();cout<<x<<" , " <<y<

我看到有很多关于这个问题的问题,但我没有解决它.你能帮我吗()?谢谢

解决方案

您已经在 actor.h 中声明了一个 Actor 类:

class 演员 {公众:演员();};

这意味着您将编写一些代码来定义此构造.这通常会在 Actor.cpp 文件中结束.

如果您尝试在没有此实现的情况下构建 Actor,您将收到来自链接器的错误,因为您缺少默认构造函数.

现在您已经声明了一个 Plane,它是 Actor 的子类:

类平面:演员{};

并且您已经定义了一个非默认构造函数:

Plane::Plane(double, double) {//做某事}

由于 PlaneActor 的子类,所以默认 Actor 的隐式构造作为 Plane 构造的一部分,并且当您声明将有一个实现时,链接器正在等待它.由于您从未在代码中定义它,因此链接器此时会失败.

有些简单的解决方案是在 actor.h 中添加一个简单的构造函数;即:

class 演员 {上市:Actor() {}//替换 ;和 {}演员(双x0,双y0);空移动();双 pos_x();双 pos_y();静态常量 int ARENA_W = 500;静态常量 int ARENA_H = 500;};

<块引用>

现在,对于这里的行为 - movepos_xpos_y 方法都没有声明为 virtual,所以它们不会在 Plane 中被重载;他们只是被取代了.这可能会在您的课程稍后出现.

i'm working on an exercise at uni and every time i try to compile the main.cpp i got always the same error.

actor.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 (subclass of 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;
}

i saw there are many questions about this problem but i didn't fix it. can you help me please()? thank you

解决方案

You've declared a class Actor in actor.h:

class Actor {
    public: Actor();
};

This means that you're going to write some code that will define this construction. This would typically end up in an Actor.cpp file.

If you attempt to construct an Actor without having this implementation, you will get an error from the linker because you're missing the default constructor.

Now you've declared a Plane that's a subclass of an Actor:

class Plane : Actor {
};

and you've defined a non-default constructor:

Plane::Plane(double, double) {
   // does something
}

As Plane is a subclass of Actor, there's an implicit construction of a default Actor as part of the construction of Plane, and as you declared that there would be an implementation, the linker is expecting it. As you never defined it in the code, the linker fails at this point.

The somewhat simplistic solution is to add a trivial constructor in actor.h; namely:

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

Now, as for behaviours here - none of the move, pos_x or pos_y methods are declared virtual, so they're not being overloaded in Plane; they're simply being replaced. This may come up later in your course.

这篇关于C++ 错误::-1: 错误:找不到 x86_64 体系结构的符号 - 在 Qt-Creator 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆