[Insight-users] itk::SmartPointer - problem making code const-correct

Stuart Golodetz itk at gxstudios.net
Fri May 28 13:43:28 EDT 2010


Luis Ibanez wrote:
> <snip>
>
> 3) Please note that the construction
>
>           const    Image::ConstPointer &  ptr ....;
>
>     prevents the internal mechanisms of the SmartPointer
>     from working, since the "const" keyword prevents the "ptr"
>     variable from changing. (strictly speaking it prevents the
>     smart pointer from calling the non-const method Register()
>     on the object that it points to).
I take back what I said in the reply I just posted a minute ago (when it 
comes through on the list) - you don't need to make Register() and 
UnRegister() const methods, you just need to add a templated constructor 
like this:

template <typename T>
   SmartPointer(const SmartPointer<T>& p)
   :    m_Pointer(p.GetPointer())
   { this->Register(); }

Not sure if that causes any obvious problems at all though? It should 
only compile if p.GetPointer()'s type is convertible to m_Pointer's 
type, so I can't see an obvious problem, but there may be other things 
lurking that I've missed.

Cheers,
Stu
>   Regards,
>
>
>         Luis
>
> <snip>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100528/a8564f00/attachment.htm>


More information about the Insight-users mailing list