我想在我的 vector 中收集指向不同方法的指针(正确映射):
std::map < sf::Keyboard::Key, std::function<void()> > keyData;
现在,当我想向这个 vector 中添加一些东西时,我遇到了问题。
inputManager.addKeyToCheck(sf::Keyboard::A, std::bind(&mv::Scene::moveViewLeft, mv::Scene::getInstance()));
因为我得到这个错误:
Error C2665 'std::tuple::tuple': none of the 2 overloads could convert all the argument types
我需要存储指向不同类方法的指针,但我不知道该怎么做。任何其他解决方案或想法如何修复此代码?
最佳答案
比 std::bind
更喜欢 lambdas;它们让生活变得更轻松:
inputManager.addKeyToCheck(sf::Keyboard::A, []() {
mv::Scene::getInstance().moveViewLeft();
});
关于c++ - 指向不同方法的 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43263003/