Reputation: 19700
Here is a bit of code that I'm currently using:
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;
}
I'm getting the following error from intel 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
I'm having difficulty understanding what's wrong here. Does anyone have any ideas?
Upvotes: 2
Views: 1468
Reputation: 425
....
for_each((pair.second).begin(),(pair.second).end(),
[&objectType,&total](const Entity* entity)
{
....
});
});
....
Upvotes: -1
Reputation: 137850
You're asking for a non-const
reference to a pointer to an Entity
. The list containing that pointer is const
. You must decide between a non-const pointer or a const list.
Upvotes: 2