<div dir="ltr"><div><div><div><div>Hello Yann,<br><br></div>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.<br></div>The two following links give some insight in why ITK is implemented this way:<br><a href="https://itk.org/Wiki/ITK/Examples/Utilities/ReturnObjectFromFunction">https://itk.org/Wiki/ITK/Examples/Utilities/ReturnObjectFromFunction</a><br><a href="https://itk.org/pipermail/insight-developers/2011-April/018011.html">https://itk.org/pipermail/insight-developers/2011-April/018011.html</a><br><br></div>Hope this helps,<br></div>Francois<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 21, 2017 at 6:45 AM, asertyuio via Insight-users <span dir="ltr"><<a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div class="m_4393718566787835312markdown-here-wrapper">
      <p style="margin:0px 0px 1.2em!important">Hi Hans,</p>
      <p style="margin:0px 0px 1.2em!important">Thanks for your
        answer !</p>
      <p style="margin:0px 0px 1.2em!important">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</p>
      <pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">auto testOutput = testFilter->GetOutput();
</code></pre>
      <p style="margin:0px 0px 1.2em!important">has not the same
        behavior as</p>
      <pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important"> FilterOutputType::Pointer testOutput = testFilter->GetOutput();
</code></pre>
      <p style="margin:0px 0px 1.2em!important"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">testOutput</code>
        is a smart pointer in the second case, and a normal pointer in
        the first one.</p>
      <p style="margin:0px 0px 1.2em!important">I was wondering if
        it could interfere with the smart pointer role (for example
        causing memory leak, or wrong reference count).</p>
      <p style="margin:0px 0px 1.2em!important">After a deeper look,
        <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">New()</code>
        return a smart pointer (so with auto =, no problem) and <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">GetOutput()</code>
        a pointer. So the second code snipset just creates another
        instance of a smart pointer.</p>
      <p style="margin:0px 0px 1.2em!important">I hope what was my
        question is now clearer !<br>
        Yann</p><span class="">
      <p style="margin:0px 0px 1.2em!important">Le 21/03/2017 à
        01:43, Johnson, Hans J a écrit :</p>
      <p style="margin:0px 0px 1.2em!important"></p>
      <div class="m_4393718566787835312markdown-here-exclude">
        <p></p>
        <blockquote type="cite">
          <pre>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


</pre>
        </blockquote>
        <p></p>
      </div>
      <p style="margin:0px 0px 1.2em!important"></p>
      <div title="MDH:PHA+SGkgSGFucyw8L3A+PHA+VGhhbmtzIGZvciB5b3VyIGFuc3dlciAhPGJyPjwvcD48cD5JIHdhcyBhc2tpbmcgdGhhdCBiZWNhdXNlIHdoZW4gSSB1c2UgYXV0byBrZXl3b3JkIHdpdGggYSBmaWx0
ZXIgb3V0cHV0LCBpdCBzZWVtcyBsaWtlIGlzIHJlc3VsdCBpbiBhIG5vcm1hbCBwb2ludCB0eXBl
LCBub3QgYSBzbWFydCBwb2ludGVyLCBzbyBhIGNvZGUgd2l0aDwvcD5gYGA8YnI+YXV0byB0ZXN0
T3V0cHV0ID0gdGVzdEZpbHRlci0mZ3Q7R2V0T3V0cHV0KCk7PGJyPmBgYDxwPmhhcyBub3QgdGhl
IHNhbWUgYmVoYXZpb3IgYXM8L3A+PHA+YGBgPGJyPgpGaWx0ZXJPdXRwdXRUeXBlOjpQb2ludGVy
IHRlc3RPdXRwdXQgPSB0ZXN0RmlsdGVyLSZndDtHZXRPdXRwdXQoKTs8L3A+PHA+YGBgPC9wPjxw
PmB0ZXN0T3V0cHV0YCBpcyBhIHNtYXJ0IHBvaW50ZXIgaW4gdGhlIHNlY29uZCBjYXNlLCBhbmQg
YSBub3JtYWwgcG9pbnRlciBpbiB0aGUgZmlyc3Qgb25lLjxicj48L3A+PHA+SSB3YXMgd29uZGVy
aW5nIGlmIGl0IGNvdWxkIGludGVyZmVyZSB3aXRoIHRoZSBzbWFydCBwb2ludGVyIHJvbGUgKGZv
ciBleGFtcGxlIGNhdXNpbmcgbWVtb3J5IGxlYWssIG9yIHdyb25nIHJlZmVyZW5jZSBjb3VudCku
PC9wPjxwPkFmdGVyIGEgZGVlcGVyIGxvb2ssIGBOZXcoKWAgcmV0dXJuIGEgc21hcnQgcG9pbnRl
ciAoc28gd2l0aCBhdXRvID0sIG5vIHByb2JsZW0pIGFuZCBgR2V0T3V0cHV0KClgIGEgcG9pbnRl
ci4gU28gdGhlIHNlY29uZCBjb2RlIHNuaXBzZXQganVzdCBjcmVhdGVzIGFub3RoZXIgaW5zdGFu
Y2Ugb2YgYSBzbWFydCBwb2ludGVyLjxicj48L3A+SSBob3BlIG15IHF1ZXN0aW9uIGlzIGNsZWFy
ZXIgITxicj5ZYW5uPGJyPjxicj48ZGl2IGNsYXNzPSJtb3otY2l0ZS1wcmVmaXgiPkxlIDIxLzAz
LzIwMTcgw6AgMDE6NDMsIEpvaG5zb24sIEhhbnMgSiBhIMOpY3JpdCZuYnNwOzo8YnI+PC9kaXY+
PGJsb2NrcXVvdGUgY2l0ZT0ibWlkOjdEOTRGMDE2LTE4QTctNEY4OS05MzYxLTQ4NkFBNjU2MUU4
RUB1aW93YS5lZHUiIHR5cGU9ImNpdGUiPjxwcmUgd3JhcD0iIj5ZYW5uLAoKSXQgd2lsbCB3b3Jr
IG9ubHkgaWYgeW91IGFyZSBjb21waWxpbmcgd2l0aCBDKysxMSwgYW5kIHlvdSBoYXZlIG5vIGlu
dGVudGlvbiBvZiBzaGFyaW5nIHlvdXIgY29kZSB3aXRoIG90aGVycyB3aG8gbWF5IG5vdCB1c2Ug
QysrMTEgc3ludGF4LgoKSVRLIHByb3BlciBjdXJyZW50bHkgbWFpbnRhaW5zIGJhY2t3YXJkcyBj
b21wYXRpYmlsaXR5IHdpdGggb2xkZXIgdmVyc2lvbnMgb2YgQysrLgoKSGFucwoKCjwvcHJlPgoK
        PC9ibG9ja3F1b3RlPjxicj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div>
    </span></div>
  </div>

<br>______________________________<wbr>_______<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br></div>