5.4. Destructor

The destructor for the element is of the standard format:


C++
SoModelMatrixElement::~SoModelMatrixElement()

If your element requires special cleanup—for example, because it allocates memory space that needs to be freed—the destructor should also perform that work.

At this point, you might be thinking, “What about the element constructor? Don't I need to write one?” Actually, you don't. The constructor for an element is built into the header, and you do not have access to it. There are only two times when an element instance is created:

  • When the first instance of an element is created and put on the stack by the state

  • When a new element instance is pushed onto the stack

In the first case, the virtual init() method is used after creating the first instance of the element. In the second case, the virtual push() method is used after creating each subsequent instance of the element. You can override the virtual init() and push() methods if your element class requires its own default value or other special behavior.