[Insight-users] Automatically deducing SmartPointer function template parameter

David Doria daviddoria at gmail.com
Sat Jan 7 20:13:34 EST 2012


On Sat, Jan 7, 2012 at 6:12 PM, Bradley Lowekamp <blowekamp at mail.nih.gov> wrote:
> Hello David,
>
> You can simply overload the function with both the pointer and the
> SmartPointer arguments as was done with the constructor here:
>
> http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1Image.html
>
> Brad

That does work:

template <typename TImage>
void MyFunctionSmartPointer(typename itk::SmartPointer<TImage> image){}

typedef itk::Image<int, 2> ImageType;
ImageType::Pointer image = ImageType::New();

MyFunctionSmartPointer(image);

However, now it won't accept a normal pointer!

MyFunctionSmartPointer(image.GetPointer());

I understand that you said to overload the function, but as I
mentioned I have a whole bunch of these functions and it would be very
annoying to have to duplicate all of them (even though of course the
smart pointer version would just call the non-smart pointer version of
the same name with .GetPointer() on the image parameter).

I would have thought the smart pointer parameter would have been happy
to accept a normal pointer, but I guess not?

David


More information about the Insight-users mailing list