Write a program of assignment operator overloading


 

/* Write a program of assignment operator overloading*/

#include<iostream.h>

#include<conio.h>

class abc

{

public:

int x;

float y;

public:

abc(int,float);

void operator=(abc a);

void display();

};

abc::abc(int one,float two)

{

x=one;

y=two;

}

void abc::operator=(abc a)

{

x=a.x;

y=a.y;

}

void abc::display()

{

cout<<x<<endl<<y;

}

void main()

{

clrscr();

abc obj1(10,22.2);

abc obj2(20,33.3);

obj1=obj2;

obj1.display();

obj2.display();

getch();

}

/* output:

20

33.29999920

33.299999*/

Related Posts

Comments are closed.