Operator Overloading in C++
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;
}
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