Thursday, May 7, 2009

CONSTRUCTOR

Constructor
It is a Special Member function in C++. It is used to initialize value for the variable with in the class

The constructor functions have some special characteristics:
• They should be declared in the public section.

• The constructor name and class name must be same.

• They are invoked automatically when the objects are created.

• They do not have return types, not even void and therefore, they cannot return values.

• They cannot be inherited, though a derived class can call the base class constructor.

• Like other C++ functions, they can have default arguments.

• Constructors cannot be virtual.

• We cannot refer to their addresses.

• An object with a constructor (destructor) cannot be used as a member of a union.

• They make implicit calls to the operators new and delete when memory allocation is required.


Constructor can be classified into four types,

they are


1. Default Constructor

2. Parameterize Constructor

3. Constructor Overloading

4. Copy Constructor

No comments:

Post a Comment