我想写重载运算符,它增加了enum类型:
#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));
};但它抛出了一个错误:
错误:'&‘标记前应有初始值设定项
为什么以及如何修复它?
我需要这个操作符来迭代Type进行“红绿灯”模拟:
Ampel Ampel::weiter(){
if(zustand == Type(rot_gelb)){
zustand = Type(grun);
return Ampel(zustand);
}
++zustand;
return Ampel(zustand);
}https://stackoverflow.com/questions/47714121
复制相似问题