Hey, I am making a small network game and I suddenly got some problems with my player class, specially when trying to call the getName function and using the second constructor I get this error:
1>------ Build started: Project: RPG, Configuration: Release Win32 ------
2>------ Build started: Project: Server, Configuration: Release Win32 ------
1>Compiling...
2>Compiling...
1>playerHandler.cpp
2>playerHandler.cpp
1>player.cpp
2>main.cpp
1>main.cpp
2>Linking...
2>playerHandler.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall player::getName(void)" (?getName@player@@QAEAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
2>playerHandler.obj : error LNK2001: unresolved external symbol "public: __thiscall player::player(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,float,float)" (??0player@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@MM@Z)
2>C:\Users\Samuli\Documents\Visual Studio 2008\Projects\RPG\Release\Server.exe : fatal error LNK1120: 2 unresolved externals
2>Build log was saved at "file://c:\Users\Samuli\Documents\Visual Studio 2008\Projects\RPG\Server\Release\BuildLog.htm"
2>Server - 3 error(s), 0 warning(s)
1>Linking...
1>Generating code
1>Finished generating code
1>Embedding manifest...
1>Build log was saved at "file://c:\Users\Samuli\Documents\Visual Studio 2008\Projects\RPG\RPG\Release\BuildLog.htm"
1>RPG - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code for player class
player.h
#ifndef __PLAYER_H_
#define __PLAYER_H_
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
class player
{
private:
std::string charName;
float health;
float mana;
float X;
float Y;
int level;
float expirience;
bool isAlive;
sf::Sprite model;
public:
player(std::string name);
player(std::string name, float x, float y);
sf::Sprite & getModel();
void move(const sf::Input & keyboard, sf::RenderWindow & window1);
float & getX();
float & getY();
float & getHealth();
float & getMana();
bool & getStatus();
int & getLevel();
float & getExpirience();
std::string & getName();
friend sf::Packet & operator << (sf::Packet & Packet, player& p);
friend sf::Packet & operator >> (sf::Packet & Packet, player& p);
};
#endif
sf::Packet & operator << (sf::Packet & Packet, player& p);
sf::Packet & operator >> (sf::Packet & Packet, player& p);
Player.cpp
#include "player.h"
player::player(std::string name):
health(100), mana(100), X(20), Y(20), level(1), expirience(0), isAlive(true), charName(name)
{
model.SetColor(sf::Color(0, 123, 123, 128));
model.SetPosition(X,Y);
model.SetScaleX(40.f);
model.SetScaleY(40.f);
}
player::player(std::string name, float x, float y):
health(100), mana(100), X(x), Y(y), level(1), expirience(0), isAlive(true), charName(name)
{
model.SetColor(sf::Color(0, 123, 123, 128));
model.SetPosition(X,Y);
model.SetScaleX(40.f);
model.SetScaleY(40.f);
}
sf::Sprite & player::getModel()
{
return model;
}
void player::move(const sf::Input & keyboard, sf::RenderWindow & window1)
{
if (keyboard.IsKeyDown(sf::Key::Down))
Y += 0.1f;
else if(keyboard.IsKeyDown(sf::Key::Up))
Y -= 0.1f;
else if(keyboard.IsKeyDown(sf::Key::Right))
X += 0.1f;
else if(keyboard.IsKeyDown(sf::Key::Left))
X -= 0.1f;
model.SetPosition(X,Y);
window1.Draw(model);
}
float & player::getExpirience()
{
return expirience;
}
float & player::getX()
{
return X;
}
float & player::getY()
{
return Y;
}
float & player::getHealth()
{
return health;
}
float & player::getMana()
{
return mana;
}
bool & player::getStatus()
{
return isAlive;
}
int & player::getLevel()
{
return level;
}
std::string & player::getName()
{
return charName;
}
// Pakettien omat ylikuormitetut operaattorit
sf::Packet & operator << (sf::Packet & Packet, player& p)
{
return Packet << p.X << p.Y << p.charName;
//return Packet << p.getExpirience() << p.getExpirience() << p.getLevel() << p.getMana() /*p.getModel()*/ << p.getStatus() << p.getX() << p.getY();
}
sf::Packet & operator >> (sf::Packet & Packet, player& p)
{
return Packet >> p.X >> p.Y >> p.charName;
}