定义一个结构体 NumScope 以及一个枚举 Type
struct NumScope
{
double max = 0.0;
double min = 0.0;
bool isMaxSet = false;
bool isMinSet = false;
};
enum Type
{
INT, DOUBLE
}
实例化并赋值
NumScope ns;
ns.isMaxSet = true;
ns.isMinSet = true;
ns.max = 10.0;
ns.min = 5.0;
Type t = Type::INT;
测试语句
std::cout << std::to_string(t == Type::INT ? static_cast<int>(ns.max) : ns.max)) << std::endl;
测试结果

疑问
为什么没有输出10? 是 t == Type::INT 有问题还是 static_cast<int>(ns.max) 没有执行?