I made a class to store commands to be sent from the player to the server. I overloaded the insertion and extraction operators, but it is giving me linking errors. It has been a while since I overloaded an operator so I might be doing it wrong, which I am imaging is the case. Any help would be greatly appreciated.
Here is the file that overloads the operators. It is Visual Studio 2010 Express using SFML 1.6.
#pragma once
#include <SFML\Network.hpp>
class CommandFlags
{
public:
bool moveForward;
bool moveBackward;
bool moveLeft;
bool moveRight;
bool shoot;
bool unshoot;
sf::Uint16 mouseX;
sf::Uint16 mouseY;
CommandFlags();
CommandFlags(const CommandFlags &source);
};
sf::Packet &operator >>(sf::Packet &packet, CommandFlags getFlags)
{
return packet >> getFlags.mouseX >> getFlags.mouseY >> getFlags.moveBackward >> getFlags.moveForward >> getFlags.moveLeft >> getFlags.moveRight >> getFlags.shoot >> getFlags.unshoot;
}
sf::Packet &operator <<(sf::Packet &packet, CommandFlags sendFlags)
{
return packet << sendFlags.mouseX << sendFlags.mouseY << sendFlags.moveBackward << sendFlags.moveForward << sendFlags.moveLeft << sendFlags.moveRight << sendFlags.shoot << sendFlags.unshoot;
}
Here is the error I get:
1>server-player.obj : error LNK2005: "class sf::Packet & __cdecl operator<<(class sf::Packet &,class CommandFlags)" (??6@YAAAVPacket@sf@@AAV01@VCommandFlags@@@Z) already defined in commandflags.obj
Here is the two files for that class:
#include "server-player.h"
Player::Player()
{
}
Player::Player(sf::IPAddress setIP, int setPort, std::string setName)
{
port = setPort;
ip = setIP;
name = setName;
}
sf::IPAddress Player::GetIP()
{
return ip;
}
std::string Player::GetName()
{
return name;
}
void Player::SetName(std::string setName)
{
name = setName;
}
void Player::Fill(sf::IPAddress playerIP, std::string playerName, unsigned short int playerPort)
{
ip = playerIP;
name = playerName;
port = playerPort;
}
bool Player::IsOccupied()
{
return slotOccupied;
}
void Player::SetCommandFlags(CommandFlags flags)
{
playership->SetCommands(flags);
}
#pragma once
#include <string>
#include <queue>
#include <SFML/Network.hpp>
#include "commandflags.h"
#include "server-ship.h"
class Player
{
private:
sf::IPAddress ip;
unsigned short int port;
std::string name;
bool slotOccupied;
ServerShip *playership;
public:
Player();
Player(sf::IPAddress setIP, int setPort, std::string setName);
sf::IPAddress GetIP();
std::string GetName();
void SetName(std::string setName);
void Fill(sf::IPAddress playerIP, std::string playerName, unsigned short int playerPort);
bool IsOccupied();
void SetCommandFlags(CommandFlags flags);
void SetPlayerShip(ServerShip *setShip);
ServerShip* GetPlayerShip();
};