AW: [Insight-users] Primary question: SmartPointer

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


Hi, yann,
you are right. The problem is that the allocations are all local in
certain function. When the function is over, the allocation is also
deleted.=20
I figure it out by defining a global pointer.

Anyway, thanks for your answer.

Cheers,

Chunyan Jiang

-----Urspr=FCngliche Nachricht-----
Von: Yann GAVET [mailto:yann.gavet@univ-st-etienne.fr]=20
Gesendet: Mittwoch, 5. Mai 2004 14:19
An: Jiang
Cc: ITK
Betreff: Re: [Insight-users] Primary question: SmartPointer

Well, Im no itk expert but I would say that you should write
ImageType::Pointer ClassA::OneFilter()
{
...
}

I think that ImageType::New() is not useful because you allocate a new=20
image and then you loose the reference.

yann.

Jiang wrote:

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




More information about the Insight-users mailing list