Sep 6, 2015 at 4:43am UTC
Error: warning C4717: 'operator>>' : recursive on all control paths, function will cause runtime stack overflow
1 2 3 4 5 6 7 8 9
sf::Packet& operator <<(sf::Packet& _packet, const SERVER_REQUEST& _request)
{
return _packet << static_cast <sf::Int8>(_request);
}
sf::Packet& operator >>(sf::Packet& _packet, SERVER_REQUEST& _request)
{
return _packet >> static_cast <SERVER_REQUEST>(_request);
}
Server_Request:
1 2 3 4
enum SERVER_REQUEST
{
REQUEST_JOIN
};
sf::Packet takes, amount other things, most numerical types. I'm trying to convert my enum to an int, send it, then get the enum from the packet on server side.
(if needed):
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Packet.php
Last edited on Sep 6, 2015 at 7:20am UTC
Sep 8, 2015 at 3:40am UTC
bump. i had this working before but i forgot what i did. i feel like it's something simple that i'm missing :/
Sep 8, 2015 at 4:23am UTC
Don't you think these should be a friend functions.
Sep 8, 2015 at 4:42am UTC
They're not in a class. I just put them in my network header header with all my other network structs.
so now it runs, but when I use the '>>' operator I get a stack overflow.
"Stack overflow (parameters: 0x00000001, 0x00FA2FD4)."
.h:
1 2
sf::Packet& operator <<(sf::Packet& _packet, const NETWORK_REQUEST& _request);
sf::Packet& operator >>(sf::Packet& _packet, NETWORK_REQUEST& _request);
.cpp:
1 2 3 4 5 6 7 8 9 10 11
sf::Packet& operator <<(sf::Packet& _packet, const NETWORK_REQUEST& _request)
{
return _packet << static_cast <sf::Int8>(_request);
}
sf::Packet& operator >>(sf::Packet& _packet, NETWORK_REQUEST& _request)
{
return _packet >> static_cast <NETWORK_REQUEST>(_request);
}
Pls help.
Last edited on Sep 8, 2015 at 5:41am UTC
Sep 8, 2015 at 5:49am UTC
Why do you have two versions? What does the second do?
Sep 8, 2015 at 6:00am UTC
What do you mean? There's one input and one output operator overload. I need to input data to packets and also get data from packets.
How it works:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//send data
sf::Packet packet;
NETWORK_REQUEST request = NETWORK_REQUEST::REQUEST_JOINGAME;
packet << request;
socket.send(packet);
//get data
sf::Packet packet;
NETWORK_REQUEST request;
socket.receive(packet);
packet >> request;
if (request == NETWORK_REQUEST::REQUEST_JOINGAME)
blah blah blah
sf::Packet doc if needed to understand:
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Packet.php
There's also a compiler warning: 'operator>>' : recursive on all control paths, function will cause runtime stack overflow
Last edited on Sep 8, 2015 at 6:09am UTC
Sep 8, 2015 at 6:06am UTC
My error.
If you had only one of these, would it compile? In other words, is only one of the two the problem?
The input operator calls itself recursively. Why don't you read into, say sf::Int8
variable, and then store the value into _request?
Sep 8, 2015 at 6:12am UTC
You can store ints in an enum? How would that fix it?
>The input operator calls itself recursively.
can you explain why that happens? I'm not that experienced with overloading operators yet.
Sep 8, 2015 at 8:48am UTC
DELETED - I was looking at the wrong operator
Last edited on Sep 8, 2015 at 11:24am UTC