首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >枚举运算符重载C++中'&‘标记前应有初始值设定项

枚举运算符重载C++中'&‘标记前应有初始值设定项
EN

Stack Overflow用户
提问于 2017-12-08 20:08:09
回答 0查看 204关注 0票数 0

我想写重载运算符,它增加了enum类型:

代码语言:javascript
复制
#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进行“红绿灯”模拟:

代码语言:javascript
复制
Ampel Ampel::weiter(){
    if(zustand ==  Type(rot_gelb)){
        zustand = Type(grun);
        return Ampel(zustand);
    }
    ++zustand;
    return Ampel(zustand);
}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47714121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档