Jon Berndt wrote:

I'm not positive, but it seems (roughly) like a vector push_back() operation
causes the d'tor to be called after the first element is stored. To me, this
seems to say that the push_back() operation copies the existing stored
element[s] to a new location (resizing the container) and destroys the old
copy of the object stored in the vector. I'm looking into this in
Stroustrup, but if anyone has any insights to share on this I'd be
interested to hear them.

If you have


vector<MyClass> list;

then

  MyClass listItem;
  list.push_back(listItem);

will add a copy to the list. To avoid that, use

vector<MyClass *> list;

To avoid surprises, it's always a good idea to declare a private copy constructor and assignment operator by default if your class doesn't need a public one.


All the best,



David


_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to