[vtk-developers] Smart pointer declaration macro?

Brad King brad.king at kitware.com
Fri Jan 8 21:22:39 EST 2010


David Cole wrote:
> It's unfortunate that we've had two +1's and two -1's... that leaves us
> at 0 for the moment. I guess that and the fact that it's Friday makes it
> fairly easy to put off a decision until at least next week. ;-)

IMO ideally the syntax would be

   vtkSmartPointer<vtkPoints> instance = vtkPoints::New();

but for backwards compatibility we have to return a raw pointer
from ::New() methods.  Other options have been proposed.

Karthik Krishnan wrote:
> Or have these as typdefs and/or factory methods in a VTK class, as is
> done in ITK (that would be internally handled via macros in the
> class), so that usage syntax looks like.
>
>   vtkPoints::SmartPointer = vtkPoints::SmartNew();
> or
>   vtkPoints::SmartPointer instance(1);

I don't think a type::SmartPointer typedef is necessary.
It just adds more header dependencies.  Currently the
vtkSmartPointer is useable in .cxx files without touching
vtk headers.

David Gobbi wrote:
> There are other ways to reduce the repetition, without using macros:
>
> 1) Add a new constructor argument for smart pointers:
>
> vtkSmartPointer<type> instance(1); // create an smart pointer and
> allocate an object at the same time
> vtkSmartPointer<type> instance(0); // create a smart pointer with
> "null" as the initial pointer

This is a reasonable suggestion since we never pass constructor
arguments to ::New() methods.

-Brad



More information about the vtk-developers mailing list