重载运算实例

来源:互联网 发布:云计算数据中心建造 编辑:程序博客网 时间:2024/05/18 05:11
#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;}

0 0
原创粉丝点击