RAD Studio
ContentsIndex
PreviousUpNext
Constructors

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.

class X {
public:
   X();   // class X constructor
};

A class X constructor cannot take X as an argument:

class X {
public:
   X(X);                      // illegal
};

The parameters to the constructor can be of any type except that of the class it’s a member of. The constructor can accept a reference to its own class as a parameter; when it does so, it is called the copy constructor. A constructor that accepts no parameters is called the default constructor.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!