[ITK] [ITK-users] auto keyword and New() smart pointer
Francois Budin
francois.budin at kitware.com
Tue Mar 21 08:38:34 EDT 2017
Hello Yann,
Indeed, you are correct. New() will return a smart pointer, but other
methods will return a pointer, so you cannot use the keyword "auto" with
these other methods.
The two following links give some insight in why ITK is implemented this
way:
https://itk.org/Wiki/ITK/Examples/Utilities/ReturnObjectFromFunction
https://itk.org/pipermail/insight-developers/2011-April/018011.html
Hope this helps,
Francois
On Tue, Mar 21, 2017 at 6:45 AM, asertyuio via Insight-users <
insight-users at itk.org> wrote:
> 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
>
>
>
>
>
> _____________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20170321/642610cb/attachment.html>
-------------- next part --------------
_____________________________________
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
More information about the Community
mailing list