Search code examples
c++sfml

Shifting to the argument of a setter


Hello I want to use shifting operator >> to push something into an argument of function. To do it I can do the following, but is there any shorter and better answer?

int foo;
packet >> foo;
setFoo(foo);

The >> operator in packet takes an int. Also setFoo is constant and takes a constant reference of the integer. The packet is an instance of sf::Packet from SFML Network library.


Solution

  • sf::Packet seems to have a member class called sf::getData()

    You can presumably do setFoo(*(int*)packet.getData()) but it isn't a "better" answer compared to your code.