如果我这样写:
typedef enum {
foo_1,
foo_2
}foo ;
我发现我可以用
int footype = foo::foo_1
在 c++ 中
我可以直接使用
int footype = foo_1
in c,
那么有没有一种方法可以编写同时适用于 C++ 和 C 的相同代码?代码在一个只有一种结构的头文件中。
最佳答案
int footype = foo_1;
这将在 C 和 C++ 中编译。
int footype = foo::foo_1;
此语法仅对于 C++11 的强类型枚举是必需的。
关于c++ - C 和 C++ 中的 ENUM 类型和用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13272480/