我的原型(prototype)文件中有两个枚举,它们定义了几乎相同的值。
是否可以删除其中一个并留下一个别名以保持所有代码正常工作?
例子:
enum A {
a = 0;
b = 1;
}
enum B {
a = 0;
b = 1;
}
我想在 C++ 中使用类似 typedef 的东西:
enum A {
a = 0;
b = 1;
}
typedef A B;
我没有在文档中找到这个。有任何解决方法吗?
最佳答案
这是一个老问题,但如果有人仍然感兴趣, 现在可以使用 protobuf 在枚举上创建别名
enum EnumAllowingAlias {
option allow_alias = true;
UNKNOWN = 0;
STARTED = 1;
RUNNING = 1;
}
enum EnumNotAllowingAlias {
UNKNOWN = 0;
STARTED = 1;
// RUNNING = 1; // Uncommenting this line will cause a compile error inside Google and a warning message outside.
}
如官方文档中所述here .您只需要通过添加 option allow_alias = true;
关于c++ - 是否可以在 google protobuf 中为类型(枚举或消息)定义别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17533549/