[Insight-users] More flexible assignment for itk::SmartPointer

Bill Lorensen bill.lorensen at gmail.com
Tue Nov 25 12:12:43 EST 2008


Maarten,

Why not do the dynamic cast yourself? Then you can have control if the
dynamic_cast fails. I think we do this several times in itk.

Bill

On Tue, Nov 25, 2008 at 11:04 AM, Maarten Nieber <hallomaarten at yahoo.com> wrote:
> Hi,
>
> I hope I am not restarting any old discussions, but I would like to be able
> to assign an itk::SmartPointer to another pointer that has a compatible
> type, for example:
>
> itk::Image<3, double>::Pointer image = itk::Image<3, double>::New();
> itk::ImageBase<3>::Pointer p = image;
>
> Note that boost::shared_ptr works like this.
> The behaviour could be achieved using a templated copy constructor for
> itk::SmartPointer:
>
> template< class TObjectType2 >
> SmartPointer(const SmartPointer<TObjectType2>& rhs)
> {
>     // do a dynamic_cast here, and assign the result to rhs
> }
>
> Would this be a good idea?
>
> Best regards,
> Maarten
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list