This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Operator Overloading | |
#include<iostream> | |
#include<conio.h> | |
using namespace std; | |
class rectangle | |
{ | |
int length; | |
public: | |
rectangle(int c) | |
{ | |
length=c; | |
} | |
rectangle operator+(rectangle ob)//copy constructor | |
{ | |
int g; | |
g=length+ob.length; | |
return g; | |
} | |
void show() | |
{ | |
cout<<"\nlength\t"<<length; | |
} | |
}; | |
int main() | |
{ | |
rectangle r1(4); | |
rectangle r2(5); | |
//rectangle r3; | |
r1.show(); | |
r2.show(); | |
rectangle r3=r1+r2; | |
r3.show(); | |
getch(); | |
return 0; | |
} |
Comments
Post a Comment
Thanks for the comment and don't forget to subscribe.