SFML community forums

Help => Network => Topic started by: Danetta on December 28, 2016, 08:33:53 am

Title: Packet << Vector
Post by: Danetta 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.
Title: Re: Packet << Vector
Post by: fer_t 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