Boost logo

Boost Users :

From: kdsfinger_at_[hidden]
Date: 2006-03-20 12:59:04


hi, Boost users

Suppose I created a large data in a function and want to return it back to
where the function was called. I want to return the pointer so that the deep
copy of the large data is not needed and memory leak is nicely handled. Can
someone let me know how to do it? Here is something come up in my mind:

 boost::shared_ptr< std::vector<int> > getV(){
 boost::shared_ptr< std::vector<int> > v;
 v->push_back(1);
 v->push_back(2);
// bla bla bla
 return v;
 }

 int main(){
 boost::shared_ptr< std::vector<int> > v = getV();
 std::cout << v->at(0);
 return 0;
 }

 I got the following message when run the program:
 /usr/include/boost/shared_ptr.hpp:253: T*
 boost::shared_ptr<T>::operator->() const [with T = std::vector<int,
 std::allocator<int> >]: Assertion `px != 0' failed. Aborted

 How can I get it correct? Is there any deep copy when the getV() return
 the shared_ptr?

Thanks a lot.

zl2k



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net