Quote:Original post by TokikoQuote:Are you SURE you want that last line to read like that, and not like this??(*_collisionMap)[ second ]->addCollision( new Collision( second ) );
Sorry there was a typo with the first collision and it should be passing second. So if I didn't type that wrong, you would be correct :P
Well then you can simplify the code even more...
void CollisionSet::addCollision( GameComponent* component ){ if ( _collisionMap->find( component ) == _collisionMap->end() ) (*_collisionMap)[component] = new CollisionQueue(); (*_collisionMap)[component]->addCollision( new Collision( component ) );}// And you would just call it twice, once for each component... // since they don't depend on one another in the original functionaddCollision( first );addCollision( second );
Quote:Now with this line here. I was going to use that earlier, but I figured that it wouldn't work since you are trying to find the value paired with first, but if that key hasn't been added, how can you make a new collision? So I guess it will insert a new element if it is not found?(*_collisionMap)[first] = new CollisionQueue();
Exactly. But you should check for the element first or you would erase the old CollisionQueue, if it already existed.
And I'm with Zahlman... is there a compelling reason to dynamically create a map? You could just use the map as an instance variable, and then you don't have to destroy it later.