[英]Should I place my enum out or inside of my int main()?
My code works, altough I have a feeling that it could be improved, especially my enum which is currently inside the main()
function. 我的代码可以正常工作,尽管我有种可以改进的感觉,尤其是当前位于
main()
函数内部的枚举。
I've tried placing my enum outside of the int main
function, it still works, I personally think it wouldn't be very presentable. 我试图将我的枚举放置在
int main
函数之外,但它仍然可以正常工作,我个人认为这不是很合适。
int main()
{
enum element {
ICE, FIRE, EARTH, WIND, NONE
};
..The rest of the code..
return 0;
}
Any tips would be much appreciated. 任何提示将不胜感激。
reference to C++ How to translate my code to OOP with classes and functions? 对C ++的引用如何使用类和函数将我的代码转换为OOP?
Outside. 外。 You will want to use this enum for a class, the class may be defined someplace else, requiring the enum.
您将需要将此枚举用于一个类,该类可能在其他地方定义,需要枚举。 So it should be outside.
所以应该在外面。
Also, maybe better to use an enum class in modern C++. 同样,在现代C ++中使用枚举类可能更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.