[vtkusers] Using vtkDenseArray as a member variable

David Doria daviddoria+vtk at gmail.com
Fri Nov 13 09:03:11 EST 2009


On Fri, Nov 13, 2009 at 8:05 AM, Jeff Baumes <jeff.baumes at kitware.com> wrote:
> vtkDenseArray<double> is a vtkObject derivative like most everything
> else in VTK. That means you cannot ever store a normal, stack-based
> object like this, because C++ tries to call the default constructor on
> it when it is initialized, but the default constructor is protected,
> hence the error. You need to declare it (or any other vtkObject
> derivative member or local variable) as a pointer, and use ::New() in
> the constructor of the class to initialize it.
>
> Jeff

Jeff,

Ah yes, I forgot about the protected default constructor when I was
playing with this. What started the problem is still unresolved
though. If I indeed declare a pointer as the member variable

class vtkDenseArray;
class vtkMyClass : public vtkPolyDataAlgorithm
{
...	
private:
  vtkDenseArray<double>* OutputGrid;
};

and initialize the object in the constructor in the implementation file:

#include "vtkDenseArray.h"
...
vtkMyClass::vtkMyClass()
{
  this->OutputGrid = vtkDenseArray<double>::New();
}

The errors are:
error: 'vtkDenseArray' is not a template
and
error: template argument required for 'class vtkDenseArray'

Here are the complete files if necessary:
http://www.vtk.org/Wiki/Non-SmartPointer_Template_Member_Variable

Thanks,

David



More information about the vtkusers mailing list