1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| class OverLoad{ public: int value = 0; int num = 0; OverLoad(){ } OverLoad(int value,int num = 0){ this->value = value; this->num = num; } OverLoad operator +(const OverLoad&a){ this->value += a.value; this->num += a.num; return OverLoad(this->value,this->num); } void get_value()const{ cout<<"the value is "<<this->value<<endl; }
};
void OverLoadTest(){ OverLoad a(10,5),b(20,5); OverLoad c; c = a + b; c.get_value(); }
|