楽しみのためだけに:
#include <iostream>
struct Expr {
int value;
enum oper { plus = '+', minus = '-', times = '*', div = '/', nop = 0 } op;
Expr(int value, oper op) : value(value), op(op) { }
Expr(int value) : value(value), op(nop) {}
Expr operator+() { return Expr(value, plus); }
Expr operator-() { return Expr(value, minus); }
Expr operator*() { return Expr(value, times); }
Expr operator,(const Expr& rhs) {
Expr result(value, op);
switch(op) {
case '+': result.value += rhs.value; break;
case '-': result.value -= rhs.value; break;
case '*': result.value *= rhs.value; break;
case '/': result.value /= rhs.value; break;
}
return result;
}
};
int main () {
Expr x(0), a(1), b(2);
x = ( + a , b );
std::cout << x.value << "\n";
}