#include <iostream>
enum class Color { RED, GREEN };
Color& operator++(Color& source)
{
switch (source)
{
case Color::RED: return source = Color::GREEN;
case Color::GREEN: return source = Color::RED;
}
}
int main()
{
Color c1{ 1 };
Color c2 = Color::RED;
++c1; // OK
std::cout << (int)c1 << std::endl;
c2++; // error
std::cout << (int)c2 << std::endl;
return 0;
}
I overloaded ++ operator but it only works from left hand side. What is the reason behind it?
Is it related to the way I do overloading or is it related to lvalue-rvalue concept?