Write a C++ Program to illustrate default constructor, parameterized constructor and copy constructors.
#include <iostream>
using namespace std;
class Constructors{
int value;
public:
Constructors():value(0){
cout<<"Default constructor called...";
}
Constructors(int val):value(val){
cout<<"Parameterized constructor called...";
}
Constructors(const Constructors &temp){
cout<<"Copy constructor called...";
this->value = temp.value;
}
void printValue(){
cout<<value<<endl;
}
};
int main(){
Constructors constructor;
constructor.printValue();
constructor = Constructors(2);
constructor.printValue();
Constructors constructor3(constructor);
constructor3.printValue();
return 0;
}
Comments
Leave a comment