RE: const-correct smartpointers



> The C++ Language mapping (section 1 pages 12 and 13) from the 
> OMG site 
> has the following sample code (I have cut a lot out):
> 
> class A;
> typedef A* A_ptr;
> 
> class A_var : public _var {
>   operator const A_ptr& () const { return ptr_; }
>   operator A_ptr& () { return ptr_; }
>   A_ptr operator->() const { return ptr_; }
> protected:
>   A_ptr ptr_;
> };
> 
> Note that in all three cases the const conversion operator does not 
> return a pointer to a const object but a rather a pointer to 
> a mutable 
> object. The const on the conversion operator prevents only the _var 
> object from being modified. It doesn't protect the pointed to object. 
> Notice how the operator-> also is declared const but returns 
> a pointer 
> to a mutable object. Which is quite consistent with the 
> behaviour of T* 
> versus T* const.

Bizarre, but if that's the spec then that's the spec.

Anyway, I still think the changes I described are necessary, so I'll press
on. Feel free to do anything else in the meantime.

Murray Cumming
murrayc usa net
www.murrayc.com 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]