It was very difficult to come up with a name ... (I am not a native speaker of English.)
struct A { int value; A operator+(int i) const { A a; a.value=value+i; return a; }; }; int main(){ A a; a.value=2; a=a+2; return 0; }
This code compiles / works as expected, but when I change a = a + 2 to a = 2 + a, it will no longer compile. GCC gives me this error:
no match for "operator+" in "2 + a"
Is there a way to somehow make 2 + work like +2?
source share