Constructor:- Constructor is a special member function which has same name as a class name and is used to initialize object during compile time of program.
Declaring constructor in derived class If a base class contains a constructor with one or more arguments then it is mandatory for the derived class to have a constructor and pass the argument to the base class constructor. A header line of derived constructor function contains two parts separated by a colon (:) First part provides the declaration of the arguments that are passed to the derived constructor and the second part lists the function calls to the base constructors.
Example:
#include<iostream.h>
#include<conio.h>
class base
{
int a;
public:
base(int x)
{
a=x;
}
void displaybase()
{
cout<<a;
}
};
class derived:public base
{
int b;
public:
derived (int x,int y):base(x)
{
b=y
}