How can I properly make prefix and postfix operators for any type?
For example, I have this enum class
:
enum class Traffic_light { green, yellow, red };
I try to create the operator overloads like:
Traffic_light operator++(int)
{
return Traffic_light::green;
}
Traffic_light operator++()
{
return Traffic_light::red;
}
But this does not work.
Traffic_light tl = Traffic_light::green;
++tl; // Error
tl++; // Error
error: no match for ‘operator++’
How does one overload operators in general?
I would like to see a general guide for any type.