Next: The Data Up: Creating a New Previous: Inheritance from F_NodeClass

The Constructor

If a class definition contains a member function whose name is the name of the class, that is a very special function called the constructor. Any time C++ creates a new class object, it will execute the constructor for that class.

In the example, the constructor is defined by the line


  erpNode() { type = erpType; version = 0;}

Here erpNode() is the name of the function (the constructor) and the braces enclose the block of statements to be executed when the constructor is called. There must be at least one one statement, initializing type. type is a data member of type F_NodeType inherited from the class F_Node. As a minimum, the constructor for any node class you define must initialize the type variable in this way. If you are using versioning (discussed below in Section ), you should also initialize the version variable to the latest version number (here we initialize it to be zero).

There is a lot more to learn about constructors and you are referred to a C++ text for the details. Now you know just enough to make the package work.


walter@
Wed Aug 10 11:53:26 PDT 1994