正在调用运算符()语法
Calling operator() syntax
ProjectileManager继承自EntityManager,EntityManager将其作为受保护成员:
struct EntityDeallocator{
void operator()(std::pair<sf::String,std::shared_ptr<Entity>> p)const{
p.second.reset();
std::cout << "object removed" << std::endl;
}
};
ProjectileManager更新功能:
void ProjectileManager::update(double frameTime){
for(std::map<sf::String,std::shared_ptr<Entity>>::const_iterator it = entities.begin();it!=entities.end();it++){
it->second->update(frameTime);
it->second->getObject()->draw(*SfmlFramework::Singleton()->window);
if(it->second->getObject()->getSprite()->GetPosition().x > SfmlFramework::Singleton()->window->GetWidth() || it->second->getObject()->getSprite()->GetPosition().y > SfmlFramework::Singleton()->window->GetHeight()){
//I want to call EntityDeallocator on it
}
}
}
如何在it
上调用EntityDeallocate?我尝试过EntityDeallocate(it),但它表示it
是一个未引用的局部变量。
说明什么是未引用的局部变量?张贴错误字符串,而不是错误字符串的近似值。。
至于如何调用非静态成员函数,它们总是相同的。您需要一个成员函数和一个将其绑定到的对象。
struct Fred
{
operator()(){}
}
//later on...
Fred fred;
fred();
虽然与您的问题不直接相关,但您可能会发现此链接对理解C++如何调用成员函数非常有帮助。http://www.parashift.com/c++-faq lite/pointers-to-members.html
相关文章:
- C++语法运算符功能?
- C++ 运算符修改/元编程策略,用于不那么冗长的语法
- 无效删除运算符语法
- std::is_invocable 用于测试任意方法是否存在的语法(不仅是运算符())
- 这个typedef和转换运算符语法是什么意思
- C++ lambda 和运算符语法
- 如何使用 Boost Spirit x3 编写具有两个后操作数语法的二进制运算符?
- 将强制转换运算符重载到 std::map 的正确语法是什么
- 奇怪的语法构造 - 应用于 typedef 的运算符 () 使用 VS2015 成功编译
- 如何使用删除 [] 运算符清除动态分配的内存?(无法使用常规删除语法清除)
- 适用于全局模板运算符指定模板参数的适当语法
- C 中的controad()括号的语法运算符
- 全局新运算符调用语法
- 模板的赋值运算符(成员函数)实现的正确语法
- 这个奇怪的条件运算符语法是什么
- 为什么在使用初始化语法时不调用转换运算符,为什么 clang 错误消息看起来是错误的
- 运算符重载中的C++语法不明确
- 使用范围解析运算符时的语法错误
- 正在调用运算符()语法
- 条件运算符语法