--- In Boost-Users@yahoogroups.com, Hossein Haeri
Dear all,
I'm a newbie in boost!
I want to know what the following means:
int a = 5; const boost::shared_ptr<int> sp(&a);
Does it mean that the following line is an error?
*sp = 7;
If so, what are the guarantees? Is there any documented guarantee? (I couldn't find anything in the documentation. Excuseme if I'm careless!)
I'd say you could call any of the 'const' member functions (e.g. operator*(), operator->(), get(),...,etc), but the returned type is a non-const pointer. Since operator*() is a const member function, it is legal on a const shared_ptr<T>. The '=', then, applies to the non-const shared ptr returned, not to the shared_ptr<T> object, itself. Note also, that you're supposed to initialized shared_ptr<T> with a *dynamically* allocated T (use new), because it will call 'delete' on the ptr when the last reference disappears. So you are wrong to initialize it with the address of a stack variable. jh