#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;
#define A system("pause")
const int sz=10;
class INT{
int value;
public:
INT(int v=0):value(v){}
INT(const INT &h){
value=h.value;
}
INT& operator=(const INT& h){
value=h.value;
return *this;
}
INT& operator+(const INT& h){
value+=h.value;
return *this;
}
INT& operator-(const INT& h){
value-=h.value;
return *this;
}
INT& operator*(const INT& h){
value*=h.value;
return *this;
}
INT& operator/(const INT& h){
value/=h.value;
return *this;
}
friend ostream& operator << (ostream& out,const INT& h){
out<<h.value;
return out;
}
friend istream& operator >> (istream& in,INT &h){
in>>h.value;
return in;
}
};
int main(){
INT B(5),C(B),D=C;
cout<<B+C<<endl;
cout<<D-C<<endl;
cout<<B*C<<endl;
cout<<C/C<<endl;
A;
return 0;
}
重载运算实例
最新推荐文章于 2024-05-22 14:58:37 发布