我的班级Game
有一个成员EntityManager entityManager_
。
该类EntityManager
有一个私有成员和返回Player player_
的公共 getter 函数。Player &EntityManager::getPlayer()
player_
该类Player
具有例如函数void startMoving()
和sf::Vector2f getPosition() const
。
现在,我可以毫无问题地entityManager_.getPlayer().startMoving();
从我的Game
班级中调用,但是当我尝试例如以下代码来获取玩家的位置时:
sf::Vector2f playerPosition = entityManager_.getPlayer().getPosition();
我收到以下错误:
智能感知:
EntityManager Game::entityManager_
Error: the object has type qualifiers that are not compatible with the member function
object type is: const EntityManager
输出:
game.cpp(261): error C2662: 'EntityManager::getPlayer' : cannot convert 'this' pointer from 'const EntityManager' to 'EntityManager &'
Conversion loses qualifiers
我尝试const
从播放器的 getPosition 函数中删除,但没有任何改变。
我知道这可能与该有关,const
但我不知道要更改什么!有人可以帮我吗?