Why do people use enums in C++ as constants while they can use const?
2013-04-20 21:32
501 查看
Often you'll see enum { SOMETHING = 2232; } (like that; unnamed enum with one value only) instead of
const int SOMETHING = 2232;. It's because enum never gets any storage while const variable is still a variable and will get (static) storage if the compiler can't proove it won't need one, which it often can't.
const int SOMETHING = 2232;. It's because enum never gets any storage while const variable is still a variable and will get (static) storage if the compiler can't proove it won't need one, which it often can't.
相关文章推荐
- Why do a lot of #defines in the kernel use do { ... } while(0)?
- Why I can't use non-string key in the myMap[myKey] expression? And what to do now?
- Why do a lot of #defines in the kernel use do { ... } while(0)?
- Why can't I ...? Why won't ... work?" What to do in case of problems
- Question 10: Given the following program snippet, what can we conclude about the use of dynamic_cast in C++?
- [!] Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfil
- Why do many Collection classes in Java extend the abstract class and implement the interface as well
- Do not use lsnrctl and sqlplus as SYSDBA in RAC
- Do people forget a foreign language they don't use regularly? How fast does it happen?
- When do we use Initializer List in C++?
- Why do people use gradient boosted decision trees to do feature transform?
- vue Do not use built-in or reserved HTML elements as component id: nav
- vue引入组件无法显示且报错[Vue warn]: Do not use built-in or reserved HTML elements as component id: header
- Why do I get EOF exception while reading a datainputstream in java?
- Kernel: Do NOT use global variable as possible as you can 尽量不使用全局变量
- Why can't we change access modifier while overriding methods in C#?
- Can we use function on left side of an expression in C and C++?
- Question 16: Which of the following methods can a developer use to override the default terminate() function in C++?
- Question 20: Which allocator member function do standard containers use to acquire storage for their elements in C++?
- People seldom do what they believe in. They do what is convenient, then repent.