Genlib's constructor tag

Syntax:

constructor class [ (arguments) ] [ : member-initialization ] {
initialization code
}

The constructor tag delimits code that should be added to any constructors for class. If the code requires arguments to the constructors, then those arguments are specified in arguments using normal C++ argument syntax (including default values, etc.). If there are const instance variables in class, their initialization is specified in member-initialization, again using standard C++ syntax.

Note that components you have included might also provide constructors for class. Genlib will automatically put an opening and closing curly brace around the code you provide with constructor so that any local variables you declare will not conflict with those declared in other constructors for class.

Since multiple constructors for class may exist, one somewhat complicated issue is what the argument lists for the constructors generated for class will contain. In the simple case where no component (nor the genlib input file) offers more than one constructor for class, then class will have one constructor whose argument list is a concatenation of the argument lists of all provided constructors, in order from the first included component (which is typically the component that provides the baseline functionality for class) through the last included component. If the genlib input includes a constructor for class, that constructor's arguments will appear in the same relative position in the argument list as the constructor is in the input file relative to class's included components.

If a component (or the genlib input file) offers multiple constructors for class, then a corresponding number of constructors will be generated, each generated constructor using one of the provided constructors. This means that if several components offer multiple constructors, the final number of generated constructors will be the product of the number of provided constructors; e.g. if 3 separate components offer 2 constructors apiece for class, then the final number of generated constructors will be 8 (2x2x2).

Since generated constructor argument lists contain concatenated argument lists from various components as well as the genlib input file, it would seem to be problematic for a component writer to know what arguments to use with a constructor. For this reason, it is strongly recommended that the following guidelines for constructor argument lists be followed:

If these guidelines are followed, invoking a constructor with just the arguments required by the baseline component should always work. For clarity, it is also strongly recommended that component inclusion requests be placed at the top of genlib input files.