My question is, what does returning an assignment expression mean, as in my code example? I have an enumeration and I redefine the ++: operator. Therefore, in my short example, you can switch between leagues, but in the code I do not understand. The code compiles and works fine.
the code:
enum Traficlight {green, yellow, red }; Traficlight& operator++(Traficlight& t) { switch (t) { case green: return t = Traficlight::yellow; //Here <-- case yellow: return t = Traficlight::red; //Here <-- case red: return t = Traficlight::green; //Here <-- default: break; } } int main() { Traficlight Trafic = Traficlight::green; Trafic++; if (Trafic == Traficlight::yellow) { cout << "Light is Yellow" << endl; } string in; cin >> in; }
Which means "return t = Traficlight :: yellow", why I can not return "Traficlight :: yellow".
source share