vtkSmartPointer<CMyClass> does not compile


I would like to pass a regular c++ class to my vtkSmartPointer object, obviously I have difficulty to compile it! What I did I drived it from vtkObject

class vtkFile : public vtkObject {

std>>vectorstd::string s;

vtkFile(). : s({1",“2”}){}

any suggestions appreciated!


In order to be wrapped into vtkSmartPointer (and itk::SmartPointer), a class must have public methods Register() and UnRegister which increase and decrease reference count. When created, objects have a reference count of one. Once the reference count reaches 0, the objects are to be de-allocated.

In case of deriving from vtkObject, you might need vtkNew macro and maybe some other stuff too. Instead of starting from scratch, take a similar existing class which derives from vtkObject and modify it.

1 Like

Hi @dzenanz,

Thanks, I know about reference count and register and unregister, I have used Unknown in days of ATL pop, and active, etc. by modifying you mean I drive from a class drived from vtkObject and then add my stuff in that include data members and public methods and protected, virtual, … and then it would be wrapped by vtkSmartPointer? do I need to call the class for instance vtkMyClass otherwise it would not be wrapped by vtkSmartPointer?


I don’t think it needs to be called vtkMyClass. The vtkName convention is purely for human benefit. I don’t know where vtkTypeMacro is defined, but look at a simple class like vtkAppendPoints to get a feel of what needs to be defined and how it looks like.