SFML community forums

Help => Network => Topic started by: McKnas on May 24, 2011, 09:12:22 pm

Title: sf::Packet and std::string doesn't work
Post by: McKnas on May 24, 2011, 09:12:22 pm
I've been playing a bit with tcp sockets and packets to maybe use it later for some simple client server game.
Most of the time it works fine but right now i can't figure out what I'm doing wrong.
When i try to insert a certain combination of variables into a package it doesn't want to compile.
My code is  something like this:
Code: [Select]
sf::Uint8 id;
std::string str;
char msgtype;

packet >> id >> msgtype >> str; //doesn't work

packet >> str; //works

packet >> id >> msgtype; //works

The error i recieve is this:
Code: [Select]
error: no match for "operator>>" in "(((int)((sf::Packet*)packet.sf::Packet::operator>>(((sf::Uint8&)(& id))))->sf::Packet::operator bool()) >> ((int)msgtype)) >> str"
Title: sf::Packet and std::string doesn't work
Post by: Laurent on May 24, 2011, 10:01:29 pm
There's no operator >> for char. sf::Packet only defines operators >> for fixed-size integer types (like sf::Int8).

The problem is that the implicit conversion to bool is chosen, which results in "bool >> char" -- both are integer types, so it's a right-shift operation.

The solution is to use fixed-size types in packets, and on my side I'll fix it so that there's no more inappropriate implicit conversion to bool.