#include <cstdio> #include <iostream> using namespace std; class Int32 { int num; public: Int32(int num = 0) : num(num) {} ~Int32() {} int value() { return num; } Int32 & operator - (int x) { cout << "Postfix of -" << endl; return *this; } Int32 & operator -- (int x) { cout << "Postfix of --" << endl; return *this; } }; int main() { Int32 x(100); x--; x-; // [Error] expected primary-expression before ';' token x.operator-(0); return 0; } From the above code I overloaded postfix increment and postfix unary minus. I know postfix unary minus doesn't make sense, but I wonder why I have compilation error for x- and don't have any issue with x-- and x.operator-(0) operations.
I compiled this code in DevC++ and I got following error.
[Error] expected primary-expression before ';' token What is wrong with x- ?
x-;fails because the language grammar doesn't allow it.x.operator-()syntax.-operator", it's a "binary infix-operator".