#include <iostream>
#include "strange_plus.h"
using namespace std;
int main() {
integer a, b;
int t1, t2, ans;
t1 = a + b;
t2 = ++a;
cout << t1 << endl;
cout << t2 << endl;
ans = a+(++b);
cout << ans << endl;
return 0;
}strange_plus.h:#include <string.h>
class integer {
public:
integer() {
data = 1;
}
~integer() {}
friend int operator + (const integer i1, const integer i2) {
int temp1 = i1.data;
int temp2 = i2.data;
int temp3 = 0;
int ans = 0;
while (temp1 || temp2) {
temp3 = temp3 * 10 + ((temp1 % 10 + temp2 % 10) % 10);
temp1 /= 10;
temp2 /= 10;
}
while (temp3) {
ans = ans * 10 + temp3 % 10;
temp3 /= 10;
}
return ans;
}
int operator ++ () {
int temp[10];
memset(temp, 0, sizeof(temp));
int temp_int = data;
int i = 0;
while (temp_int) {
temp[i++] = temp_int % 10;
temp_int /= 10;
}
for (int j = 0; j < i; j++) {
temp[j] = (temp[j] + 1) % 10;
}
int ans = 0;
for (int j = i - 1; j >= 0; j--) {
ans = ans * 10 + temp[j];
}
data = ans;
return ans;
}
private:
int data;
};然后报错了,看错误信息:原文:http://blog.csdn.net/u012925008/article/details/44576115