在 gcc-4.5 下打印 0,在 gcc-4.6 下打印 1。
#include <iostream>
enum VenueId: char {};
int
main (int argc, char ** argv)
{
VenueId v = (VenueId)'P';
std::cout << (v=='P') << std::endl;
return 0;
}
最佳答案
根据标准,VenuedId
具有 char
类型作为基础类型,因此 v
应包含 char 'P'
,v == 'P'
应该产生 true。
§ 7.2 枚举声明
Each enumeration defines a type that is different from all other types. Each enumeration also has an underlying type. The underlying type can be explicitly specified using enum-base; if not explicitly specified, the underlying type of a scoped enumeration type is int. In these cases, the underlying type is said to be fixed. Following the closing brace of an num-specifier, each enumerator has the type of its enumeration.
关于c++ - 这是(枚举 : char {}) a gcc bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19423626/