Vector2f contains only 2 floats, so it doesn't really matter if you return it by value of by reference. However for bigger objects, use const references to avoid unnecessary copies.
In the meantime, I got used to copy sf::Vector2f always. I don't think it will be slower. As a parameter, you can directly modify the copy and don't have to instantiate a local object. Besides, copies are syntactically more beautiful...
However, returning a copy instead of a const reference has a real advantage. Let's look at a const reference implementation, there seems to be everything fine.
const sf::Vector2f& Player::GetPosition() const
{
return MyPosition;
}
Okay, due to an implementation change, MyPosition isn't a member anymore. Instead, the position is calculated from the tile index at which the player is standing (just an example).
const sf::Vector2f& Player::GetPosition() const
{
return sf::Vector2f(MyTileX * TileSize, MyTileY * TileSize);
}
Now we get a problem because we return a reference to a local temporary object*. This wouldn't happen when using a copy. Like this, you can keep the interface. This is particularly important at virtual functions inside a polymorphic hierarchy.
By the way, sorry for little off-topic
____
*) Note that the C++ rule which allows const-references to be bound at temporary objects doesn't apply here because we're dealing with return values.
The temporary to which the reference is bound [...] persists for the lifetime of the reference except as specified below. [...]
A temporary bound to the returned value in a function return statement (6.6.3) persists until the function exits.