Risking being laughed at for bad coding, I still have a question that has been bugging me lately. "Unresolved external symbol". I have gotten this error a few times now, and I really want to know exactly what it means and why it is showing up. The code parts that are causing this are:
Player.cpp
#include "Player.h"
#include "Window.h"
Player::Player()
{
Image.LoadFromFile("Animal.tga");
Image.CreateMaskFromColor(sf::Color(255,0,255),0);
Sprite.SetImage(Image);
Sprite.SetCenter(10.f, 10.f);
}
int PlayerMovement()
{
sf::Event KeyPress;
bool up = Player::up;
bool down = Player::down;
bool left = Player::left;
bool right = Player::right;
bool shoot = Player::shoot;
int SpeedMultiplier = Player::SpeedMultiplier;
if (KeyPress.Type == sf::Event::KeyPressed)
{
switch (KeyPress.Key.Code)
{
case sf::Key::Up:
Player::up = true;
break;
case sf::Key::Down:
Player::down = true;
break;
case sf::Key::Left:
Player::left = true;
break;
case sf::Key::Right:
Player::right = true;
break;
case sf::Key::LShift:
Player::SpeedMultiplier = 3;
case sf::Key::Space:
Player::shoot = true;
default:
break;
}
}
if (KeyPress.Type == sf::Event::KeyReleased)
{
switch (KeyPress.Key.Code)
{
case sf::Key::Up:
up = false;
break;
case sf::Key::Down:
down = false;
break;
case sf::Key::Left:
left = false;
break;
case sf::Key::Right:
right = false;
break;
case sf::Key::LShift:
SpeedMultiplier = 1;
default:
break;
}
}
/* //MOVING THE PLAYER SPRITE.
if(up)
{
Player::Sprite.Move((cos(Player::Sprite.GetRotation()*3.14159265/180)*3)*Player::SpeedMultiplier, (sin(Player::Sprite.GetRotation()*3.14159265/180)*-3)*Player::SpeedMultiplier);
}
if(down)
{
Player::Sprite.Move((cos(Player::Sprite.GetRotation()*3.14159265/180)*-3)*Player::SpeedMultiplier, (sin(Player::Sprite.GetRotation()*3.14159265/180)*3)*Player::SpeedMultiplier);
}
if(left)
{
Player::Sprite.Rotate(6);
}
if(right)
{
PLayer::Sprite.Rotate(-6);
}
while (shoot)
{
//App.Draw(FireSprite);
//FireSprite.SetDirection(AnimalSprite);
//FireSprite.Move(cos(BulletAngle*3.14159265/180)*3, sin(BulletAngle*3.14159265/180)*-3);
//RenderTarget(FireSprite);
}*/
}
Player.h
#ifndef PLAYER_H
#define PLAYER_H
#include "Window.h"
#include "Enemy.h"
class Player
{
public:
Player();
sf::Image Image;
sf::Sprite Sprite;
int XCord();
int YCord();
static bool up;
static bool down;
static bool left;
static bool right;
static bool shoot;
static int SpeedMultiplier;
private:
int PosX;
int PosY;
};
int PlayerMovement();
#endif
Can you point out what is causing it and why it is a negative thing? I want to understand the errors so I can work with them even better in the future.
Notes:
The sfml packets are all under the Window.h header.
Full error list:
1>Player.obj : error LNK2001: unresolved external symbol "public: static bool Player::right" (?right@Player@@2_NA)
1>Player.obj : error LNK2001: unresolved external symbol "public: static bool Player::left" (?left@Player@@2_NA)
1>Player.obj : error LNK2001: unresolved external symbol "public: static bool Player::up" (?up@Player@@2_NA)
1>Player.obj : error LNK2001: unresolved external symbol "public: static int Player::SpeedMultiplier" (?SpeedMultiplier@Player@@2HA)
1>Player.obj : error LNK2001: unresolved external symbol "public: static bool Player::down" (?down@Player@@2_NA)
1>Player.obj : error LNK2001: unresolved external symbol "public: static bool Player::shoot" (?shoot@Player@@2_NA)
Thank you so much in advance.