Here’s a simplified version of the code I’m using:
namespace BasketNovel {
void Engine::BuryEntities()
{
std::list<Entity*>::iterator iter = p_entities.begin();
while (iter != p_entities.end())
{
if ( (*iter)->getAlive() == false )
{
delete (*iter);
iter = p_entities.erase( iter ); //.erase returns next element
}
else iter++;
}
}
}
I’m getting the following warning from Intel Static Analysis:
BasketNovel.cpp(567): warning #12221: slicing of object “iter” passed as actual argument 2 in call to “std::_List_iterator > > std::list >::erase(std::_List_const_iterator > >)” occurs due to implicit type conversion
I believe that this is basically saying that I’m causing an implicit type conversion in:
iter = p_entities.erase( iter );
(note: I get the same warning even if I change my code to: p_entities.erase( iter++ ); )
I don’t quite understand what I’m “slicing” in the above.
What exactly does this mean and how I should go about solving this warning? I’d rather slightly convoluted code than turning off warning messages completely.
Object Slicing is the fact of copying/moving only part of an object, this occurs in general with Base/Derived couples:
and can lead to nastiness.
Here though, this is just a false positive…
Yes, certainly.