Bon, j'avais pas envie de refaire un Thread, donc voici un autre problème avec la surcharge d'opérateur
#pragma once
#include <SFML\Network.hpp>
#include <SFML\System.hpp>
#include <SFML\Graphics.hpp>
#include <iostream>
#include <string>
#include <vector>
#include "ChatFeed.h"
#include "ChatNetworking.h"
#define NOMESSAGE "~$nomessage$~"
typedef enum CommandCode
{
CHANGE_NAME,POKE,DISCONNECT,SHUTDOWN_SERVER,GOOF
}CommandCode;
class ChatPacket
{
public:
ChatPacket();
ChatPacket(std::string author, std::string message,std::string timestamp);
ChatPacket(CommandCode cmdcode, std::string commandarg);
~ChatPacket();
std::string message = NOMESSAGE;
std::string author;
std::string timestamp;
CommandCode commandcode;
std::string commandarg;
};
sf::Packet& operator <<(sf::Packet& packet, const ChatPacket& chatpacket)
{
return packet << chatpacket.author << chatpacket.message << chatpacket.timestamp << chatpacket.commandcode << chatpacket.commandarg;
}
sf::Packet& operator >>(sf::Packet& packet, ChatPacket& chatpacket)
{
return packet >> chatpacket.author >> chatpacket.message >> chatpacket.timestamp >> chatpacket.commandcode >> chatpacket.commandarg;
}
Le Compilo me hurle dessus
Erreur 1 error C2678: '>>' binaire : aucun opérateur trouvé qui accepte un opérande de partie gauche de type 'sf::Packet' (ou il n'existe pas de conversion acceptable) c:\users\pierre\documents\visual studio 2013\projects\simplechat\simplechat\ChatPacket.h 36 1 SimpleChat
Erreur 2 error C2678: '>>' binaire : aucun opérateur trouvé qui accepte un opérande de partie gauche de type 'sf::Packet' (ou il n'existe pas de conversion acceptable) c:\users\pierre\documents\visual studio 2013\projects\simplechat\simplechat\ChatPacket.h 36 1 SimpleChat
3 IntelliSense : aucun opérateur ">>" ne correspond à ces opérandes
les types d'opérandes sont : sf::Packet >> CommandCode c:\Users\Pierre\Documents\Visual Studio 2013\Projects\SimpleChat\SimpleChat\ChatPacket.h 36 83 SimpleChat
WTF
// envoi
packet << static_cast<sf::Uint8>(command);
// réception
sf::Uint8 c;
packet >> c;
command = static_cast<CommandCode>(c);
sf::Packet& operator >>(sf::Packet& packet, ChatPacket& chatpacket)
{
sf::Uint32 it;
packet >> chatpacket.author >> chatpacket.message >> chatpacket.timestamp >> it >> chatpacket.commandarg;
chatpacket.commandcode = static_cast<CommandCode>(it);
return packet;
}
Comme ça ? :p