[Insight-users] [vtkusers] Return itkObjects

David Doria daviddoria at gmail.com
Thu Jun 7 08:56:35 EDT 2012


> Which one do you mean MeshType::pointer or MeshType?
>
> Jothy

MeshType is not an object, it is just a type (defined with 'typedef').
MeshType::Pointer is then a smartpointer to an object of type
'MeshType'.

David

>> Hi,
>> It is better to return smartpointers over regular pointers?
>>
>> Regards

If you create the object as a:

MeshType::Pointer myMesh = MeshType::New();

in the function, you'll have to return a MeshType::Pointer, or the
smart pointer will go out of scope and be destroyed. Actually, I think
in ITK that is the only way to do it (I don't have any experience with
itk::Mesh, but with itk::Image I don't think anything works correctly
if you try to create a itk::Image<float, 2>* image = itk::Image<float,
2>::New() ?)

David


More information about the Insight-users mailing list