[vtkusers] Forward declaring vtkSmartPointer

Marcus D. Hanwell marcus.hanwell at kitware.com
Mon Nov 16 14:15:14 EST 2009


On Monday 16 November 2009 14:10:39 David Doria wrote:
> I thought Jeff had resolved this the other day, but it is cropping up
>  again. (here is an example:
> http://www.rpi.edu/~doriad/VTK_List/ForwardDeclareSmartPointer/ )
> 
> The thought was that we could correctly forward declare a template class:
> 
> template <typename T> class vtkSmartPointer;
> 
> so that it could be used to define a member variable:
> 
> private:
> vtkSmartPointer<vtkTransform> Transform;
> 
> However, I'm getting:
> error: field 'Transform' has incomplete type
> 
> Any idea why this would be?
> 
I think that Transform would have to be a pointer in order for forward 
declaration to work. You have declared a local instance of  
vtkSmartPointer<vtkTransform> and so the full definition is required. Forward 
declarations can only be used when you are using pointers or references.

The smart pointer becomes fairly useless when you need to use a pointer to it 
though, as you then have to destroy it yourself and so you may as well use a 
pointer to the object.

Marcus
-- 
Marcus D. Hanwell, Ph.D.
R&D Engineer, Kitware Inc.
(518) 881-4937



More information about the vtkusers mailing list