[Insight-users] Automatically deducing SmartPointer function template parameter

Bradley Lowekamp blowekamp at mail.nih.gov
Sat Jan 7 18:12:52 EST 2012


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

========================================================
Bradley Lowekamp  
Medical Science and Computing for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov

On Jan 7, 2012, at 4:59 PM, David Doria wrote:

> I have a tons functions with this type of signature:
> 
> template <typename TImage>void MyFunction(TImage* image)
> If I create an image like this:
> 
> typedef itk::Image<int, 2> ImageType;
> ImageType::Pointer image = ImageType::New();
> 
> And pass it like this:MyFunction(image);
> 
> I get an 'undefined function' error.
> 
> It works if I explicitly specify the template
> parameter:MyFunction<ImageType>(image);
> 
> It also works if I pass the raw pointer:MyFunction(image.GetPointer());
> If I change the function parameter to:
> 
> template <typename TImage>
> void MyFunctionSmartPointer(typename TImage::Pointer image)
> 
> again it works if I explicitly specify the template parameter:
> MyFunctionSmartPointer<ImageType>(image);
> 
> but still doesn't work if I just pass the smart pointer:
> MyFunctionSmartPointer(image);
> 
> and curiously also doesn't work with the raw pointer:
> MyFunctionSmartPointer(image.GetPointer());
> 
> Is there anything that can be done to pass a smart pointer to a
> function and have it automatically deduce the type?
> 
> Thanks,
> 
> David
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120107/133b331c/attachment.htm>


More information about the Insight-users mailing list