#include<iostream>
using namespace std;
class cl
{
int a;
public:
cl();
cl(int x);
cl(cl &ob); //copy constructor
void output();
~cl();
};
cl::cl()
{
a=10;
cout<<"overloading"<<a<<endl;
}
cl::cl(int x)
{
a=x;
cout<<"overloading"<<a<<endl;
}
void cl::output()
{
cout<<a<<endl;
}
cl::~cl()
{
cout<<"destructing"<<a<<endl;
}
void f( cl ob3)
{
cout<<"monday"<<endl;
}
cl::cl(cl &ob)
{
a=ob.a;
cout<<"copy constructor"<<a<<endl;
}
int main()
{
cl ob(100),ob1,ob2(50),ob3(30);
cout<<"sunday"<<endl;
f(ob3);
cout<<"friday"<<endl;
cl ob4(500); // parameterised constructor
cl ob5=ob4; // copy constructor
cl ob6(ob); // copy constructor
}
No comments:
Post a Comment