【发布时间】:2013-01-18 04:04:20
【问题描述】:
我正在制作一个包含 Player 类的简单游戏,并制作了一个数组来在玩家被实例化时保存他们。问题是,每次运行程序时,我都会收到 LNK 2019 错误-“未解析的外部符号”。我不确定为什么会发生这种情况或如何使其正常工作。任何帮助将不胜感激。
Player *player = new Player[9];
for(int i = 0; i< world1.numPlayers;i++) // ADD PLAYERS TO ARRAY
{
Player tempplayer(3,3,5,1);
player[i] = tempplayer;
}
这是播放器类的定义:
#pragma once
class Player
{
public:
Player(int width, int height, int xPos, int health );
~Player(void);
Player();
int getWidth();
int getHeight();
int getHealth();
int getPos();
void setHealth(int newHealth);
bool isAlive();
int width;
int height;
int health;
int xPos;
};
这是确切的警告:“错误 1 错误 LNK2019:无法解析的外部符号“public: __thiscall Player::Player(void)”(??0Player@@QAE@XZ) 在函数 _main C:\Users\Alex 中引用\Documents\Visual Studio 2012\Projects\ConsoleApplication2\ConsoleApplication2\World.obj ConsoleApplication2"
【问题讨论】:
-
您是否为每个成员函数(尤其是析构函数)提供了定义?
-
链接器警告通常会显示它无法找到的内容。这通常足以确定错误的来源,或者至少指出正确的方向。你能粘贴完整的警告吗?
标签: c++