Operator Overloading in C++

in #programming6 years ago

Program 1:

#include < iostream >
using namespace std;

class Test
{
private:
int count;

public:
Test(): count(5){}

   void operator ++() 
   { 
      count = count+1; 
   }
   void Display() { cout<<"Count: "<<count; }

};

int main()
{
Test t;
// this calls "function void operator ++()" function
++t;
t.Display();
return 0;
}

Program 2:

#include < iostream >
#include < string >
using namespace std;
class ester{
int a,b;
public:
ester(){
a=0;
b=0;
}
ester(int x,int y){
a=x;
b=y;
}
ester operator+(ester s){
ester clows;
clows.a=a+s.a;
clows.b=b+s.b;
return clows;
}
void show(){
cout<<"value of a is "<<a<<endl;
cout<<"value of b is "<<b<<endl;
}
};
int main (){
ester erf1(10,30),erf2(20,40),erf3;
erf3=erf1+erf2;
cout<<endl;
erf3.show();
return 0;
}

Written in C++


Source

Made in Visual C++ IDE


Source

I hope it was helpful and you learned something from it, Thanks

Sort:  

incredible writing of C ++ programming language.
it would be more interesting again, if there is information and examples of the application

yes

I will sure to add some

you are great

yeea me too

ok ... I wait for your next post about C ++ programming language.

yeea me too

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 64455.55
ETH 3147.84
USDT 1.00
SBD 3.94