Constructors
In c++ provides a special member
function called the constructor.which enable the object to inilaze when it is
created.It is a special function its name is the same as class name.
The constructor function is invoked
whenever an object of its associated class is created.It is called constructor
because it construct the values of data members of the class.In constructor
that accepts no parameter is called the default constructor.If no such constructor is define than the compiler supplies a default
constructor.The constructor that accept parameters as a argument is called parameterized
constructor.
Characterstatices :-
Ø Constructors should
be decleare in the public section.constructor are invoke automatically when the
objects are created.They do not have return types, not even void therefore a
constructor cannot return values.
Ø Constructor can not
be inherited,but a drived class can call the base class constructor.
Ø Like c++ function a
constructor can have default arguments.
Ø Constructors cannot
be virtural
Ø It cannot refer the
address of a contructor.
Ø An object with a
constructor or distructor cannot be news as a member of union.
Ø A constructor make
implicit calls to the operators new and delete.when memory
allocation/deallocation is required.
Comments
Post a Comment