WHAT IS CONSTRUCTOR?


                       A constructor is a special member function whose task is to initialize the object of its class. It is special because its name is the same as the class name in which they define and automatically will be invoked when ever and associated class it created. It is called constructor class because it contract the value of data member of class.


            constructor may be characterized by-------
1. Parameterized constructor :
                                                     A constructor that can take argument or parameter- called parameterized constructor. In case of parameterized constructor must pass the initial value as argument to the constructor function when an object is declared. This is done by one from following------
a.By calling the constructor explicitly-----
Example:
#include<iostream.h>
#include<conio.h>
class xyz
{
int num;
public;
xyz(int x)
{
num=x;
}
void display(void)
{
cout<<"\n number="<<num;
}
};
void main()
{
xyz  a=xyz(100);  //calling constructor explicitly.
clrscr();
a.display();
getch( );

b.By calling the constructor implicitly-----
Example:
#include<iostream.h>
#include<conio.h>
class xyz
{
int num;
public;
xyz(int x)
{
num=x;
}
void display(void)
{
cout<<"\n number="<<num;
}
};
void main()
{
xyz  a(100);  //calling constructor implicitly.
clrscr();
a.display();
getch( );

2. Non parameterized constructor :
                                                             A constructor that accept no parameter or argument is called non parameterized constructor or default constructor. In c++ if know such constructor is define then the constructor supplies is default constructor.
Example:
#include<iostream.h>
#include<conio.h>
class xyz
{
int num;
public;
xyz(void)
{
num=100;
}
void display(void)
{
cout<<"\n number="<<num;
}
};
void main()
{
xyz  a;  //calling constructor implicitly.
clrscr();
a.display();
getch( );

Basic characteristic of constructor:
                                                            The basic characteristic of constructor are------
1. The name of the should be same as the class name in which they declared.
2. They should be declared in the public sector of class.
3. They do not return type,not even void and there for they cannot return value.
4. May or may not be parameterized.
5. In case of parameterized constructor they can have default argument.
6. Constructor can be overloaded.
7. Constructor can be virtual.
8. Cannot refer address of constructor.