RAD Studio
ContentsIndex
PreviousUpNext
Constructors

This section contains Constructor topics.

Name 
Description 
An object of a class with only public members and no constructors or base classes (typically a structure) can be initialized with an initializer list. If a class has a constructor, its objects must be either initialized or have a default constructor. The latter is used for objects not explicitly initialized.
Objects of classes with constructors can be initialized with an expression list in parentheses. This list is used as an argument list to the constructor. An alternative is to use an equal sign followed by a single value. The single value can be the same type as the first... more 
The default constructor for class X is one that takes no arguments; it usually has the form X::X(). If no user-defined constructors exist for a class, the compiler generates a default constructor. On a declaration such as X x, the default constructor creates the object x.
Like all functions, constructors can have default arguments. For example, the constructor  
Constructors are distinguished from all other member functions by having the same name as the class they belong to. When an object of that class is created or is being copied, the appropriate constructor is called implicitly.
Constructors for global variables are called before the main function is called. Global variable constructors are also called prior to #pragma startup functions.
Local objects are created as the scope of the variable becomes active. A constructor is also invoked when a temporary object of the class is created.  
In the case where a class has one or more base classes, the base class constructors are invoked before the derived class constructor. The base class constructors are called in the order they are declared.
For example, in this setup,  
Constructors can be overloaded, allowing objects to be created, depending on the values being used for initialization.  
A copy constructor for class X is one that can be called with a single argument of type X as follows:  
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!