Search This Blog

Monday, October 26, 2009

About Constructor

A constructor is a function that initilizes the members of an object. A constructor only knows how to build an object of its own class.
Constructors aren't automatically inherited between base and derived classes. If you don't supply one in the derived class, a default will be provided but this may not do what you want.

If no constructor is supplied then a default one is created by the compiler without any parameters. There must always be a constructor, even if it is the default and empty. If you supply a constructor with parameters then a default will NOT be created.

Some points about constructors

Constructors are just functions with the same name as the class.
Constructors are intended to initialize the members of the class when an instance of that class is created.
Constructors are not called directly (except through initializer lists)
Constructors are never virtual.
Multiple constructors for the same class can be defined. They must have different parameters to distinguish them.

2 comments :

  1. can you please tell me what's the concept of virtula in constructotrs i mean these are virtaual functions or what..please try to reply..

    ReplyDelete