Constructor is a special member function which constructs(initialize ) the data members of the object, whenever object of the class is created. Name of the constructor function is same as that of the class name.
Constructor in derived class:- When base class contains constructor then by default derived class must have constructor to supply the values for initialization of members of base class as well members of derived class. The reason is that in inheritance normally object of derived class is created and hence now it is responsibility of derived class to initialize members of base class because base class object is not created and hence base class constructor is not invoked. This mechanism is used in this program.
syntax for constructor in derived class is as below
class derived : public class base
data type var_d;
derived (data type var1, data type var2, data type var3,....., data type var_n):base(var1, var2)
when derived class constructor get invoked then it has variables for base class as well as for its own. First base class constructor values are supplied and the derived class constructor values are supplied.
Please include iostream.h and conio.h header files before declaration of class.
//PROGRAM TO IMPLEMENT MULTIPLE INHERITANCE USING CONSTRUCTOR IN DERIVED CLASS
cout<<"\nMarks obtained in test1 are "< }
cout<<"\nMarks obtained in test2 are "< }
class result:public test1, public test2
result(int x, int y):test1(x),test2(y)
cout<<"\nTotal marks are "< cout<<"\nAverage marks are "< }
cout<<"\nEnter marks in first test(out of 25)\n";
cout<<"Enter marks in second test(out of 25)\n";
class result r(m,n);