#include<iostream>
#include<conio.h>
using namespace std;
class Cp
{
private:
int roll;
string name;
public:
Cp(string,int);
Cp& operator=(const Cp & c);
void display();
};
Cp::Cp(string n,int r)
{
name=n;
roll=r;
cout << "Cp constructor is called :"<< endl;
}
Cp& Cp::operator=(const Cp& c)
{
name=c.name;
roll=c.roll;
cout << "copy assinment opetator is called :"<< endl;
return *this;
}
void Cp::display()
{
cout << name << endl << roll << endl;
}
int main()
{
Cp cop1("abdullah",45);
Cp cop2("ali",45);
cop2=cop1;
cop2.display();
getch();
return 0;
}
#include<conio.h>
using namespace std;
class Cp
{
private:
int roll;
string name;
public:
Cp(string,int);
Cp& operator=(const Cp & c);
void display();
};
Cp::Cp(string n,int r)
{
name=n;
roll=r;
cout << "Cp constructor is called :"<< endl;
}
Cp& Cp::operator=(const Cp& c)
{
name=c.name;
roll=c.roll;
cout << "copy assinment opetator is called :"<< endl;
return *this;
}
void Cp::display()
{
cout << name << endl << roll << endl;
}
int main()
{
Cp cop1("abdullah",45);
Cp cop2("ali",45);
cop2=cop1;
cop2.display();
getch();
return 0;
}