这是我目前正在使用的一些代码:
int Engine::getEntityCount(const int objectType)
{
using namespace std;
int total = 0;
for_each(p_entities.begin(), p_entities.end(),
[&objectType,&total](pair<const int, const list<Entity*>> pair)
{
for_each((pair.second).begin(),(pair.second).end(),
[&objectType,&total](Entity* &entity)
{
if ( entity->getAlive() == true && entity->getObjectType() == objectType )
++total;
});
});
return total;
}
我从英特尔 C++ 得到以下错误:
error : function "lambda [](Entity *&)->void::operator()" cannot be called with the given argument list c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\algorithm
我很难理解这里出了什么问题。有人有什么想法吗?
最佳答案
您正在请求一个指向实体
的指针的非const
引用。包含该指针的列表是 const
。您必须在非 const 指针或 const 列表之间做出选择。
关于C++ lambda 参数列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13677990/