From: Andrew Shiels (aeshiels_at_[hidden])
Date: 2004-07-29 16:05:22
Im very new to boost, and have just started to intergrate the shared_ptr smart pointer into one of my applications. I am storing a lot of pointers (to objects) in a std::vector.
typedef boost::shared_ptr<CMyClass> my_shared_ptr;
typedef std::vector<my_shared_ptr> my_shared_ptr_vector;
What i need to do is to additionally store a reference to the same objects
(in the vector) in a CListCtrl (MFC). The CListCtrl allows you to associate
a pointer with each item (row) in the list control.
Before i used shared_ptr i used to add the data as below:
CMyClass pItem = new CMyClass();
Now using shared_ptr (see below) i get a compiler error saying that it cannot convert from my_shared_ptr to DWORD.
my_shared_ptr myPtr (new CMyClass();
My second question is if i was able to add the item data as ...
...would the internal reference counter be incremented in shared_ptr?
My vector may be destroyed before my CListCtrl and I dont want the item data to be deleted until both are out of scope.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk