一个类中的枚举,带有显式范围,前C ++ 11? [英] Enums within a class, with explicit scoping, pre-C++11?
本文介绍了一个类中的枚举,带有显式范围,前C ++ 11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用VS2010,它没有C ++ 11的强类型枚举。
I use VS2010 which doesn't have the strongly typed enums of C++11. The strong typing I can live without, but all the same, I'd like to keep enumerations out of my class's namespace.
class Example{
enum Color{
red,
green,
blue
};
int Rainbows{
Color x = red; // this should be impossible
Color y = Color::green; // this is the only way at the enumerations
}
};
我的问题是,什么是最好的方式来完成这个,pre-C ++ 11? / p>
My question, is what is the best way to accomplish this, pre-C++11?
推荐答案
namespace ExampleColor {
enum Color {
red,
green,
blue
};
}
class Example {
int Rainbows{ExampleColor::Color x = ExampleColor::red};
};
这篇关于一个类中的枚举,带有显式范围,前C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文