正如标题所述,我在定义所有内容时收到链接器错误2019。关于这个最奇怪的部分是我不知道什么时候能得到它。有时候它会正常编译,有时它会给出这个 - 即使不改变代码。问题在于我的Sprite
类,我收到了这些错误:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall Sprite::Sprite(double,double)" (??0Sprite@@QAE@NN@Z) referenced in function "public: virtual void __thiscall FirstRoom::create(class GameEngine *)" (?create@FirstRoom@@UAEXPAVGameEngine@@@Z) ChoicesEngine C:\Users\paolo\documents\visual studio 2015\Projects\ChoicesEngine\ChoicesEngine\FirstRoom.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: void __thiscall Sprite::setImage(long)" (?setImage@Sprite@@QAEXJ@Z) referenced in function "public: virtual void __thiscall FirstRoom::create(class GameEngine *)" (?create@FirstRoom@@UAEXPAVGameEngine@@@Z) ChoicesEngine C:\Users\paolo\documents\visual studio 2015\Projects\ChoicesEngine\ChoicesEngine\FirstRoom.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: void __thiscall Sprite::drawSelf(class SDL2RenderLibrary)" (?drawSelf@Sprite@@QAEXVSDL2RenderLibrary@@@Z) referenced in function "public: void __thiscall GameRoom::displayUpdate(void)" (?displayUpdate@GameRoom@@QAEXXZ) ChoicesEngine C:\Users\paolo\documents\visual studio 2015\Projects\ChoicesEngine\ChoicesEngine\GameEngine.obj 1
我多次用Google搜索这个问题,没有解决问题。这是VS 2015中的项目结构,因此您知道我的.cpp文件包含在构建中。 VS Project structure
有相当多的代码,所以我为此道歉。
以下是Sprite.h
#pragma once
#include "SDL2RenderLibrary.h"
#include "Constants.h"
class Sprite
{
public:
// General positioning variables
Real x;
Real y;
// For collision checking the object
Real hitBoxLeftTop;
Real hitBoxLeftBottom;
Real hitBoxRightTop;
Real hitBoxRightBottom;
// The index of the image this is using
Int imageIndex;
// The standard contructer, nothing fancy
Sprite(Real newX, Real newY);
// Load a graphics for this sprite
void setImage(Int newIndex);
// Draw the sprite to the screen
void drawSelf(SDL2RenderLibrary graphicsHandle);
};
我不确定显示SDL2渲染库的内容是100%的必要条件,因此这里有一个粘贴bin链接:Pastebin
以下是Sprite.cpp
#include "Sprite.h"
Sprite::Sprite(Real newX, Real newY)
{
x = newX;
y = newY;
hitBoxLeftTop = 0;
hitBoxLeftBottom = 0;
hitBoxRightTop = 0;
hitBoxRightBottom = 0;
imageIndex = -1;
}
void Sprite::setImage(Int newIndex)
{
imageIndex = newIndex;
}
void Sprite::drawSelf(SDL2RenderLibrary graphicsHandle)
{
// Only render if the sprite's image isn't -1
if (imageIndex != -1)
{
graphicsHandle.CEF_RenderImage(x, y, imageIndex);
}
}
现在为FirstRoom.h
#pragma once
#include "GameEngine.h"
class FirstRoom : public GameRoom
{
public:
// Everything relating to the player
Sprite* sPlayer;
float baseSpeed;
float currentSpeed;
void create(GameEngine* newRoot);
void update();
};
最后FirstRoom.cpp
#include "FirstRoom.h"
void FirstRoom::create(GameEngine* newRoot)
{
GameRoom::create(newRoot);
// Player related things
baseSpeed = 5;
sPlayer = new Sprite(50, 50);
sPlayer->setImage(root->loadImage("player.bmp"));
addChild(sPlayer);
}
void FirstRoom::update()
{
// This frame's speed is determined by delta
currentSpeed = baseSpeed * root->display->CEV_DeltaMultiplier;
// Check movement
if (checkKey("W"))
{
sPlayer->y -= currentSpeed;
}
if (checkKey("S"))
{
sPlayer->y += currentSpeed;
}
if (checkKey("A"))
{
sPlayer->x -= currentSpeed;
}
if (checkKey("D"))
{
sPlayer->x += currentSpeed;
}
root->display->CEF_RenderText(0, 0, std::to_string(root->display->CEV_CurrentFPS), 255, 255, 255);
displayUpdate();
}
我不知道是否应粘贴GameEngine
件事,因此如果需要,请说明。这之前有用,所以我确定GameEngine
/ GameRoom
课程中的所有内容都做得很好。我再次为过多的代码道歉,我只是不知道我的问题在哪里。
提前致谢
答案 0 :(得分:0)
你的构造函数是:
Sprite(Real newX, Real newY);
我的第一个猜测是,可能有50个被认为是双倍而不是真正的'。
也许有点像:
Real x(50), y(50)
sPlayer = new Sprite(x, y);
in void FirstRoom :: create(GameEngine * newRoot)
同样适用于其他错误。即。 setImage有一个Int参数,但它接收和int / long。