#include "iostream"
using namespace std;
class counter
{
public:
counter(){itsval=0;}
counter(int initialvalue){itsval =initialvalue;}
int getitsval()const {return itsval;}
void setitsval (int x){itsval=x;}
counter operator + ( counter & rhs) {return counter(itsval + rhs.getitsval());}
private:
int itsval;
};
void main()
{
counter valone(2),valtwo(4),valthree;
valthree=valone+valtwo;
cout<<"valone "<<valone.getitsval ()<<endl;
cout<<"valtwo "<<valtwo.getitsval ()<<endl;
cout<<"valthree "<<valthree.getitsval ()<<endl;
}
最后的结果为什么是 6 呢?我怎么感觉应该是 10 呢