c++ - Use std::vector to construct a object and use it -


i need avoid additional cost of copying , destructing object contained std::vector caused this answer.

right i'm using std::vector of pointers, can't call std::vector::clear() without deleting each object before nor can use std::auto_ptr std containers.

i wanted this:

vector<myclass> myvec; myvec.push_back(); myclass &item = myvec.back(); 

this create new object default constructor , reference , work it.

any ideas on direction?

resolved: used @msalters answer @moo-juices suggestion use c++0x rvalue references take vantage of std::move semantics. based on this article.

almost there:

vector<myclass> myvec; myvec.push_back(myclass()); // decent compiler inline this, eliminating temporaries. myclass &item = myvec.back(); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -