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

Author Topic: Packet << Vector  (Read 2436 times)

0 Members and 1 Guest are viewing this topic.

Danetta

  • Newbie
  • *
  • Posts: 11
    • View Profile
Packet << Vector
« on: December 28, 2016, 08:33:53 am »
Hello.

Probably not really SFML related question, but Goggle did not helped me yet.

I need to send std::vector<sf::String> using sf::Packet.

Here is my code:

sf::Packet& operator<<(sf::Packet& packet, std::vector<sf::String>& vector)
{
        packet << vector.size();
        for (auto &i : vector) {
                packet << i;
        }
        return packet;
}

Then sf::Packet << &std::Vector<sf::String> gives me this warning:
warning C4800: 'std::vector<sf::String,std::allocator<_Ty>> *':
forcing value to bool 'true' or 'false' (performance warning) with
[
_Ty=sf::String
]

I know what does it mean in some regular cases, however, I have no idea how to apply it to Vector.


UPD: I am dumb. I updated the function declaration with "vector&", so I need to use sf::Packet << std::Vector<sf::String> and not sf::Packet << &std::Vector<sf::String>.

However, I still would like to see an explantation about which internal errors were caused by my mistake.
« Last Edit: December 28, 2016, 09:19:38 am by Danetta »

fer_t

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: Packet << Vector
« Reply #1 on: March 10, 2017, 12:50:28 am »
I think the problem is there is no function to call with parameter pointer so it casts the pointer to bool (true if not nullpointer false otherwise).
But this will trigger msvc warning about int to bool cast warning:
https://msdn.microsoft.com/en-us/library/b6801kcy.aspx

 

anything