
Overloading Constructors (Multiple Constructors) 355
int a,b,c;
public:
num(int m, int j, int k); // declaration of constructor with
arguments
void show()
{
cout<<“\na=”<<a <<“b=”<<b <<“c=”<<c;
}
};
num:: num (int m, int j, int k) // definition of constructor with
arguments
{
a=m;
b=j;
c=k;
}
main()
{
clrscr();
num x=num(4,5,7); // Explicit call
num y(1,2,8); // Implicit call
x.show();
y.show();
return 0;
}
OUTPUT
a= 4 b= 5 c= 7
a= 1 b= 2 c= 8
Explanation: In the above program, x and y are objects of class num. When objects are created,
three values are passed to the constructor. These values are assigned to the member variables.
The ...