Boost logo

Boost :

From: Rozental, Gennadiy (gennadiy.rozental_at_[hidden])
Date: 2002-10-02 14:15:09


> The correct solution, of course, is the following:
>
> void g(shared_ptr<foo const> p)
> {
> p->bar();
> p->baz(3); // Error!
> }
>
> Now, once again, we are prevented from calling foo::baz(), because
> operator->() returns foo const*. However, there are a few undesirable
> features of this setup. First, we can't declare the proper
> type from our
> typedef foo_ptr. So we have to refer to the original type,
> which binds
> us to shared_ptr explicitly (prevents us from swapping it out with a
> different pointer).

I do not believe that's a problem you can always do

typedef ..ptr<T> T_pointer;
typedef ..ptr<T const> T_const_pointer;

and define
void g( T_const_pointer )

ptr<T const> should be constructible from ptr<T> and everything will work as
expected.

Now about the class member. Let see how raw pointers behave:
              In const member function | In non-const member function |
____________________________________________________
T* could not change the pointer | could change the pointer
              could change the pointee | could change the pointee
____________________________________________________

ptr<T> behave the same

____________________________________________________
T* const could not change the pointer | could not change the pointer
              could change the pointee | could change the pointee
____________________________________________________

ptr<T> const behave the same
____________________________________________________
T const* could not change the pointer | could change the pointer
              could not change the pointee| could not change the pointee
____________________________________________________

ptr<T const> behave the same
____________________________________________________
T const* const
             could not change the pointer | could not change the pointer
             could not change the pointee | could not change the pointee
____________________________________________________

ptr<T const> const behave the same

So I do not see any reason to blame ptr<T>.

Gennadiy.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk