constructor
tagSyntax:
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 constructor
s 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 constructor
s for class.
Since multiple constructor
s 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 constructor
s, 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 constructor
s for class, then a corresponding number of constructors will be generated, each generated constructor using one of the provided constructor
s. This means that if several components offer multiple constructor
s, the final number of generated constructors will be the product of the number of provided constructor
s; e.g. if 3 separate components offer 2 constructor
s 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:
constructor
argument list, but should not use any default arguments.
constructor
should have an empty argument list.
constructor
s in a genlib input file should either be empty or consist of nothing but default arguments. Other constructor
s in the input can have non-empty argument lists.
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.