Write a program of comparsion operator overloading


 

/* Write a program of comparsion operator overloading*/

#include<iostream.h>

#include<conio.h>

class dob

{

int dd,mm,yy;

public:

dob(int d,int m,int y)

{

dd=d;mm=m;yy=y;

}

void show()

{

cout<<dd<<mm<<yy<<endl;

}

int operator==(dob d1)

{

if((dd==d1.dd)&&(mm==d1.mm)&&(yy==d1.yy))

return 1;

else

return 0;

}};

void main()

{

clrscr();

dob d(10,11,1013);

dob d3(10,11,1013);

d.show();

d3.show();

if(d==d3)

cout<<“equal”;

else

cout<<“not equal”;

getch();

}

/* output:

10111013

10111013

equal

10111013

10111012

not equal*/

Related Posts

Comments are closed.