[ITK-users] [ITK] Smartpointer as a default parameter for a function

Bradley Lowekamp blowekamp at mail.nih.gov
Tue Jul 22 08:37:43 EDT 2014


Hello,

You can use just about any object type for a default parameter, and pass parameters to the constructor too.

You want to be very careful with constructor with only one parameter especial just an integer. A constructor with just one parameter can be used for implicit conversion. Add the "explicit" keyword before to prevent this:

class A {
  explicit A(int A, PointerType ptr = NULL )
};

And that takes advantage of the implicit conversion with the smart pointer constructor.

Hope that help,
Brad

On Jul 22, 2014, at 4:49 AM, vincent ngai <vincent.ngai at gmail.com> wrote:

> Technically it should be A(int a, ImageType::Pointer ptr = ImageType::Pointer() );
> 
> But I"m not sure if parameter defaults are supported on non-POD parameter types. Why not just overload the ctor and create another 
> class A
> {
>  A(int a, ImageType::Pointer ptr);
>  A( int a );
> };
> 
> 
> On Tue, Jul 22, 2014 at 3:37 PM, <ahmed at mufradat.com> wrote:
> Hello All,
> 
> Suppose I have class like
> 
> class A{
>     public:
>     A(int a, ImageType::Pointer ptr){
>         // whatever!
>     }
> };
> 
> My question is, what's the default value for that ptr? I'd like to be able to create an instance of that class using
> 
> A myA(5);
> 
> so for the definition of the constructor of A:
> 
> A(int a, ImageType::Pointer ptr = WHAT?)
> 
> Best regards,
> Ahmed
> _____________________________________
> 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.php
> 
> 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://public.kitware.com/mailman/listinfo/insight-users
> 
> 
> 
> -- 
> Regards,
> Vincent
> _____________________________________
> 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.php
> 
> 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://public.kitware.com/mailman/listinfo/insight-users
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20140722/61e17aa7/attachment.html>


More information about the Insight-users mailing list