简体   繁体   English

我应该将枚举放置在int main()之中还是之中?

[英]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函数之外,但它仍然可以正常工作,我个人认为这不是很合适。

bookPicker.cpp bookPicker.cpp

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.

相关问题 我应该如何计算我的枚举? - How should I numerate my enum? 我应该在哪里将自己的异常存储在C ++中? - Where should I store (place) my own exceptions in C++? 我应该如何将长函数移出MainWindow(QT) - How should I move my long functions out of MainWindow (QT) Directx弄清楚我应该把相机放在哪里 - Directx Figuring out where i should put my camera 我的操作符重载没有在我的 int main 中返回? - My operator overload isn't returning in my int main? 如何公开库的枚举,以便我的代码不必键入整个命名空间即可使用该枚举? - How do I expose a library's enum, such that my code doesn't have to type out the entire namespace to use that enum? 我应该为项目使用相对包含路径,还是将include-directory放在包含路径上? - Should I use relative include paths for my project, or place the include-directory on the include path? 为什么我的插入排序函数不会更改从int main传递的数组? - Why my insertion sort function does not change the array that I passed from int main? 如何使我的构造函数和函数起作用,以便我的main()能够同时显示字符串和int数据? - How do I get my constructor and functions to work so my main() is able to display both the string and int data? Int主要在一个类内 - Int main inside a class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM