What does vtkTypeMacro() do???

In summary, what does vtkTypeMacro() do?
I see its definition here, but frankly don’t understand what the heck it is doing.

E.g. in this example - what is going on with struct Data?

class MyClass {
  struct Data : vtkObject
  {
    static Data* New();               // Pointer referencing itself?
    vtkTypeMacro(Data, vtkObject);   // ???
  };
};

Thanks!

Just look in the header vtkSetGet.h in Common/Core.

It adds Runtime Type Information (RTTI) to the VTK objects - VTK preceded the addition of this feature in C++.

1 Like

Yes, that macro definition is what I don’t understand. Can you summarize please?

It establishes the hierarchy to the parent class and defines the factory for construction of the object. This goes hand-in-hand with the vtkStandardNewMacro(MyClass), you need to place in the .cxx file. This hierarchy is central to VTK, e.g. by inheriting from vtkObject, you can add observers to objects, where a weak pointer is automatically created from the callee back to the caller. I can recommend that you just expand the macro pairs used in a .h and a .cxx to see what they expand to.

1 Like