c++ - boost::ptr_vector and pointers -


i this:

typedef x* x_pointer;  boost::ptr_vector<x_pointer> myvec; x_pointer x = new x(); myvec.push_back(x); 

in want objects referred pointer copy constructor never invoked , want ptr_vector control memory management when whole vector goes out of scope.

however, compiler complaining last line. think because i'm storing x* , not x.

x contains primitive types in case asks.

how can use ptr_vector store x*?

edit:

error : no instance of overloaded function "boost::ptr_vector<t, cloneallocator, allocator>::push_back [with t=x_ptr, cloneallocator=boost::heap_clone_allocator, allocator=std::allocator<void *>]" matches argument list  argument types are: (x_ptr)  object type is: boost::ptr_vector<x_ptr, boost::heap_clone_allocator, std::allocator<void *>>  myvec.push_back(x);                ^ 

boost::ptr_vector takes class, not pointer template parameter. should create way:

boost::ptr_vector<x> myvec;  

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -