[Insight-users] Primary question: SmartPointer

Jiang jiang@TI.Uni-Trier.DE
Wed May 5 11:12:36 EDT 2004


This is a multi-part message in MIME format.

------=_NextPart_000_0055_01C4329A.439495A0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi, ITK-users,
I have one question about how to transfer SmartPointer as return value.
The following is my part of code:
 
typedef .....ImageType
 
void ClassA::func()
{
ImageType::Pointer ResultImage = ImageType::New();
 
ResultImage=OneFilter();
}
 
ImageType* ClassA::OneFilter()
{
.......
Some filter process
.......
         return filter->GetOutput();
}
 
The program stops at ResultImage=OneFilter();
         I have debugged ClassA::OneFilter, it can work. If I don't use
ClassA::OneFilter() and ResultImage=OneFilter(), 
and put 
.......
Some filter process
.......
directly in ClassA::func(), then everything is ok. The filter->GetOutput
is correct.
I guess the problem is 
ImageType::Pointer ResultImage = ImageType::New();
ResultImage= OneFilter();
 
Is it wrong way to return SmartPoiner from one function to another
function?
How should I do?
 
 
 
Thanks a lot!
 
 
Chunyan Jiang

------=_NextPart_000_0055_01C4329A.439495A0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:filelist.xml@01C4329A.40842150">
<!--[if gte mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7,8 pt</w:DrawingGridVerticalSpacing>
  =
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEve=
ry>
  =
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:ApplyBreakingRules/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:SimSun;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:\5B8B\4F53;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
	{font-family:"\@SimSun";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	mso-pagination:none;
	font-size:10.5pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:SimSun;
	mso-font-kerning:1.0pt;}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;
	text-underline:single;}
span.EmailFormatvorlage17
	{mso-style-type:personal-compose;
	mso-style-noshow:yes;
	mso-ansi-font-size:9.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-fareast-font-family:SimSun;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:windowtext;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
 /* Page Definitions */
 @page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:42.55pt;
	mso-footer-margin:49.6pt;
	mso-paper-source:0;
	layout-grid:15.6pt;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Normale Tabelle";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]-->
</head>

<body lang=3DZH-CN link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:21.0pt;text-justify-trim:
punctuation'>

<div class=3DSection1 style=3D'layout-grid:15.6pt'>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>Hi,
ITK-users,<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>I
have one question about how to transfer <span =
class=3DSpellE>SmartPointer</span>
as return value.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>The
following is my part of code:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><span class=3DSpellE><span class=3DGramE><font =
size=3D1
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:Arial;mso-ansi-language:EN-GB'>typedef</span></font></span></=
span><font
size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'> =
&#8230;&#8230;&#8230;&#8230;&#8230;<span
class=3DSpellE>ImageType</span><o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><span class=3DGramE><font size=3D1 =
face=3DArial><span lang=3DEN-GB
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-=
ansi-language:
EN-GB'>void</span></font></span><font size=3D1 face=3DArial><span =
lang=3DEN-GB
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-=
ansi-language:
EN-GB'> <span =
class=3DSpellE>ClassA::func</span>()<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>{<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><span =
class=3DSpellE><font size=3D1
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:Arial;mso-ansi-language:EN-GB'>ImageType::Pointer</span></fon=
t></span><font
size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'> <span =
class=3DSpellE>ResultImage</span>
=3D <span class=3DSpellE>ImageType::<span =
class=3DGramE>New</span></span><span
class=3DGramE>(</span>);<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><span =
class=3DSpellE><font size=3D1
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:Arial;mso-ansi-language:EN-GB'>ResultImage</span></font></spa=
n><font
size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'>=3D<span =
class=3DSpellE><span
class=3DGramE>OneFilter</span></span><span =
class=3DGramE>(</span>);<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>}<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><span class=3DSpellE><font size=3D1 =
face=3DArial><span lang=3DEN-GB
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-=
ansi-language:
EN-GB'>ImageType</span></font></span><font size=3D1 face=3DArial><span =
lang=3DEN-GB
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-=
ansi-language:
EN-GB'>* <span class=3DSpellE>ClassA::<span =
class=3DGramE>OneFilter</span></span><span
class=3DGramE>()</span><o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>{<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<o:p></o:p></span></font></p=
>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>Some
filter process<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<o:p></o:p></span></font></p=
>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'><span
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
; </span><span
class=3DGramE>return</span> filter-&gt;<span =
class=3DSpellE>GetOutput</span>();<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>}<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'>The program stops at <span =
class=3DSpellE>ResultImage</span>=3D<span
class=3DSpellE><span class=3DGramE>OneFilter</span></span><span =
class=3DGramE>(</span>);<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'><span
style=3D'mso-tab-count:1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
; </span>I
have debugged <span class=3DSpellE>ClassA::OneFilter</span>, it can =
work. If I
don&#8217;t use <span class=3DSpellE>ClassA::<span =
class=3DGramE>OneFilter</span></span><span
class=3DGramE>(</span>) and <span =
class=3DSpellE>ResultImage</span>=3D<span
class=3DSpellE>OneFilter</span>(), <o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><span =
class=3DGramE><font size=3D1
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:Arial;mso-ansi-language:EN-GB'>and</span></font></span><font
size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'> put =
<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<o:p></o:p></span></font></p=
>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>Some
filter process<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;mso-ansi-language:EN-GB=
'>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<o:p></o:p></span></font></p=
>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><span =
class=3DGramE><font size=3D1
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:Arial;mso-ansi-language:EN-GB'>directly</span></font></span><=
font
size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'> in <span =
class=3DSpellE>ClassA::func</span>(),
then everything is ok. The filter-&gt;<span =
class=3DSpellE>GetOutput</span> is
correct.<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'>I guess the problem is =
<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><span =
class=3DSpellE><font size=3D1
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:Arial;mso-ansi-language:EN-GB'>ImageType::Pointer</span></fon=
t></span><font
size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'> <span =
class=3DSpellE>ResultImage</span>
=3D <span class=3DSpellE>ImageType::<span =
class=3DGramE>New</span></span><span
class=3DGramE>(</span>);<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><span =
class=3DSpellE><font size=3D1
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:Arial;mso-ansi-language:EN-GB'>ResultImage</span></font></spa=
n><font
size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'>=3D <span =
class=3DSpellE><span
class=3DGramE>OneFilter</span></span><span =
class=3DGramE>(</span>);<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'>Is it wrong way to return <span =
class=3DSpellE>SmartPoiner</span>
from one function to another function?<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'>How should I do?<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'>Thanks a lot!<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><font size=3D1 =
face=3DArial><span
lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:Arial;
mso-ansi-language:EN-GB'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal style=3D'text-indent:21.0pt'><span =
class=3DSpellE><font size=3D1
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:Arial;mso-ansi-language:EN-GB'>Chunyan</span></font></span><f=
ont
size=3D1 face=3DArial><span lang=3DEN-GB =
style=3D'font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:Arial;mso-ansi-language:EN-GB'> =
Jiang<o:p></o:p></span></font></p>

</div>

</body>

</html>

------=_NextPart_000_0055_01C4329A.439495A0--




More information about the Insight-users mailing list