I’m making a simple game involving a Player class and have made an array to hold players when they’ve been instantiated. The problem is, every time I run the program, I get LNK 2019 errors-“unresolved external symbol”. I am not sure why this is happening or how to get it working properly. Any help would be much appreciated.
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;
}
This is the Player Class definition:
#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;
};
Here is the exact warning: “Error 1 error LNK2019: unresolved external symbol “public: __thiscall Player::Player(void)” (??0Player@@QAE@XZ) referenced in function _main C:\Users\Alex\Documents\Visual Studio 2012\Projects\ConsoleApplication2\ConsoleApplication2\World.obj ConsoleApplication2″
You use of class pointers, instances and constructors seems kinda off.
This is what your code should look like:
EDIT: Note that this only bypasses the cause of the original link error. The linker is complaining that the default constructor,
Player::Player(void), cannot be found. If I’m not mistaken, its being called when you create your array withnew Player[9]. Declaring it should solve this error, allowing you to keep using the original code instead of my version.