Boost logo

Boost Users :

From: Hossein Haeri (powerprogman_at_[hidden])
Date: 2003-05-01 06:32:05


Dear John,

> 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.

I can't understand! Can you please describe your idea
more? Do you mean that calling a non-const member
function for shared_ptr<T> will result in acting the
desired operatio on a temporal mutable copy of the
original const version?

> 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.

Thank you very much because of recalling that to me.
But a subtle point here is that the asserion you made
is not true for all types. If T is not a scaler type,
it has some destructor, so I can call that destructor
explicitely, before the compiler does it, and before
the end of shared_ptr<T>. This way, there would be no
problem had I initiialised the share_ptr<T> with an
object of type T.

Wishes,
--Hossein

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


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