typedef unsigned short USHORT;
#include<iostream>
using namespace std;
calss Counter
{
public:
Counter();
Counter(USHORT initialValue);
~Counter(){}
USHORT getValue()const{return value;}
void setValue(USHORT x){value=x;}
Counter operator+(const Counter &);
private:
USHORT value;
};
Counter::Counter(USHORT initialValue):
value(initialValue)
{
}
Counter::Counter():
value(0)
{
}
Counter Counter::operator+(const Counter&rhs)
{
return Counter(value+rhs.getValue());
}
int main()
{
Counter varOne(2),varTwo(4),varTHree;
varThree=varOne+varTwo;
cout<<"varOne:"<<varOne.getValue()<<endl;
cout<<"varTwo:"<<varTwo.getValue()<<endl;
cout<<"varThree:"<<varThree.getValue()<<endl;
return 0;
}
————————————————
版权声明:本文为CSDN博主「WangJL0572」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/WangJL0572/article/details/130701823