# What does vtkTypeMacro() do???

**URL:** https://discourse.vtk.org/t/what-does-vtktypemacro-do/14406
**Category:** Support
**Tags:** code
**Created:** [August 13, 2024, 4:27pm UTC](https://discourse.vtk.org/t/what-does-vtktypemacro-do/14406 "2024-08-13T16:27:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 13, 2024, 4:27pm UTC](https://discourse.vtk.org/t/what-does-vtktypemacro-do/14406/1 "2024-08-13T16:27:48Z")

</div>

In summary, what does vtkTypeMacro() do?  
[I see its definition here](https://vtk.org/doc/release/4.0/html/vtkSetGet_8h-source.html#l00549), but frankly don’t understand what the heck it is doing.

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

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

```

Thanks!

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [August 13, 2024, 6:38pm UTC](https://discourse.vtk.org/t/what-does-vtktypemacro-do/14406/2 "2024-08-13T18:38:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![danlipsa](https://discourse.vtk.org/user_avatar/discourse.vtk.org/danlipsa/32/390_2.png) [@danlipsa](https://discourse.vtk.org/u/danlipsa)
#### Post date: [August 13, 2024, 6:46pm UTC](https://discourse.vtk.org/t/what-does-vtktypemacro-do/14406/3 "2024-08-13T18:46:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [August 13, 2024, 6:48pm UTC](https://discourse.vtk.org/t/what-does-vtktypemacro-do/14406/4 "2024-08-13T18:48:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [August 13, 2024, 6:53pm UTC](https://discourse.vtk.org/t/what-does-vtktypemacro-do/14406/5 "2024-08-13T18:53:36Z")

</div>

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.
