Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualfastcall22

Posted 25 July 2012 - 02:56 PM

The destructor is called automatically; do not manually call the destructor*.

Removing elements from a vector while iterating looks something like this:
vector<Object*> objects;
for ( vector<Object*>::iterator itr = objects.begin(); itr != objects.end(); /* empty */ ) {
    if ( itr->shouldBeRemoved() ) {
        delete *itr; // Release memory allocated for the object pointed by the pointer in the iterator
        itr = object.erase( itr );
    } else
        itr ++;
}

* Unless the object was constructed using placement-new.

#1fastcall22

Posted 25 July 2012 - 02:54 PM

The destructor is called automatically; do not manually call the destructor*.

Removing elements from a vector while iterating looks something like this:
vector<Object*> objects;
for ( vector<Object*>::iterator itr = objects.begin(); itr != objects.end(); /* empty */ ) {
    if ( itr->shouldBeRemoved() )
        itr = object.erase( itr );
    else
        itr ++;
}

* Unless the object was constructed using placement-new.

PARTNERS