Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Packet and std::string doesn't work  (Read 2018 times)

0 Members and 1 Guest are viewing this topic.

McKnas

  • Newbie
  • *
  • Posts: 8
    • View Profile
sf::Packet and std::string doesn't work
« 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"

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Packet and std::string doesn't work
« Reply #1 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.
Laurent Gomila - SFML developer

 

anything