I want to write overloading operator, that increments enum
type:
#include <iostream>
#include <vector>
#include <string>
#include <stdexcept>
using namespace std;
enum Type {grun,grun_blinkend,gelb,rot ,rot_gelb,gelb_blinkend}
Type& operator++(Type& color){
return color = static_cast<Type>(++static_cast<int>(Type));
};
But it throws me an error:
error: expected initializer before '&' token
Why and how can I fix it?
I need this operator in order to iterate over the Type for "traffic light" simulation:
Ampel Ampel::weiter(){
if(zustand == Type(rot_gelb)){
zustand = Type(grun);
return Ampel(zustand);
}
++zustand;
return Ampel(zustand);
}