Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

+AA_970+

vectors and push_back

This topic is 5795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, lets say I have a vector vector<MyClass> myVec; When I call: myVec.push_back(Object); //assume Object is of type MyClass is Object passed by reference or is a copy of Object placed in the vector? digital radiation [edited by - +AA_970+ on November 6, 2002 3:01:58 PM] [edited by - Stoffel on November 6, 2002 4:24:19 PM]

Share this post


Link to post
Share on other sites
Advertisement
That''s why you normally should use a vector of (smart) pointers if you''re going to use it with objects.

Share this post


Link to post
Share on other sites
It places a copy of the object in the vector--it''s the only exception-safe way to do it. Overload your copy constructor to output a message and you will see it called when you push_back.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!