Constructor Overloading C++
Very Simple Program for constructor overloading in c++
firstly i created a class with default constructor.
then i write code for overload constructor and in this constructor i have to formal arguments
then in next step i created an object “obj” to invoke class with default arguments.
and in last step i created an object “obj1” to invoke class again with to value.
?
include< iostream >;
using namespace std;
class cOverload{
private:
int res, val1, val2;
public:
//Default Constructor
cOverload(){
val1 = 10;
val2 = 20;
cout<<"Default Constructor: "<<val1<<" and "<<val2<<"\n\n";
}
// Constructor OverLoading
cOverload( int a , int b){
val1 = a;
val2 = b;
cout<<"Overload Constructor: "<<val1<<" and "<<val2<<"\n\n";
}
};
int main(){
cOverload obj; //object created with default constructor;
cOverload obj2(40,50); // object created with overLoaded constructor;
return 0;
}