My class Gamehas a member EntityManager entityManager_.
The class EntityManagerhas a private member Player player_and a public getter function Player &EntityManager::getPlayer()that returns player_.
A class Playerhas, for example, functions void startMoving()and sf::Vector2f getPosition() const.
Now I can call entityManager_.getPlayer().startMoving();from my class without any problems Game, but when I try, for example, the following code to get the player’s position:
sf::Vector2f playerPosition = entityManager_.getPlayer().getPosition();
I get the following error:
IntelliSense:
EntityManager Game::entityManager_
Error: the object has type qualifiers that are not compatible with the member function
object type is: const EntityManager
Conclusion:
game.cpp(261): error C2662: 'EntityManager::getPlayer' : cannot convert 'this' pointer from 'const EntityManager' to 'EntityManager &'
Conversion loses qualifiers
I tried to remove the constplayer from the getPosition function, but nothing changed.
I know that this probably has something to do with const, but I can't figure out what to change! Can someone please help me?