簡體   English   中英

C ++錯誤:-1:錯誤:在Qt-Creator中找不到架構x86_64的符號

[英]c++ error: :-1: error: symbol(s) not found for architecture x86_64 - in Qt-Creator

我在uni進行練習,每次嘗試編譯main.cpp時,我總是遇到相同的錯誤。

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

我看到有很多關於此問題的問題,但我沒有解決。 你能幫我嗎()? 謝謝

您已經在actor.h聲明了一個Actor類:

class Actor {
    public: Actor();
};

這意味着您將要編寫一些代碼來定義此構造。 這通常會以Actor.cpp文件結尾。

如果您嘗試在沒有此實現的情況下構造Actor ,則會從鏈接器中收到錯誤消息,因為缺少默認的構造函數。

現在,您已聲明一個Plane ,該PlaneActor的子類:

class Plane : Actor {
};

並且您已經定義了一個非默認的構造函數:

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

由於Plane是的子類Actor ,有一個默認的隱式建築Actor作為部分建築Plane ,並且當你宣稱會有一個實現中,接頭期待它。 由於您從未在代碼中定義它,因此鏈接器此時會失敗。

較為簡單的解決方案是在actor.h添加一個瑣碎的構造actor.h 即:

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

現在,作為行為在這里-沒有任何的movepos_xpos_y方法被聲明為virtual ,所以他們不會在超負荷Plane ; 他們只是被替換。 這可能在您的課程稍后出現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM