[ITK-users] auto keyword and New() smart pointer

asertyuio asertyuio at yahoo.fr
Tue Mar 21 06:45:07 EDT 2017


Hi Hans,

Thanks for your answer !

I was asking that because when I use auto keyword with a filter output,
it seems like is result in a normal point type, not a smart pointer, so
a code with

|auto testOutput = testFilter->GetOutput(); |

has not the same behavior as

|FilterOutputType::Pointer testOutput = testFilter->GetOutput(); |

|testOutput| is a smart pointer in the second case, and a normal pointer
in the first one.

I was wondering if it could interfere with the smart pointer role (for
example causing memory leak, or wrong reference count).

After a deeper look, |New()| return a smart pointer (so with auto =, no
problem) and |GetOutput()| a pointer. So the second code snipset just
creates another instance of a smart pointer.

I hope what was my question is now clearer !
Yann

Le 21/03/2017 à 01:43, Johnson, Hans J a écrit :

> Yann,
>
> It will work only if you are compiling with C++11, and you have no intention of sharing your code with others who may not use C++11 syntax.
>
> ITK proper currently maintains backwards compatibility with older versions of C++.
>
> Hans
>
>
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20170321/f8e28a31/attachment.html>


More information about the Insight-users mailing list