Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
重複の可能性: #define、enum、または const を使用する必要がありますか?
最近、列挙値を使用して定数を定義すると便利であることがわかりましたが、const ints、#defines と定数の列挙値を使用することの長所と短所を知りたいですか?
C では常にキーワードが存在するとは限らなかったため、for 定数の使用#defineは C の遺物 だと思います。代わりにconst使用できるようになりました。const intに関してはenum、C++11 はenumチェックする価値のあるいくつかの優れた機能を提供します。何らかの形で関連する複数の定数を使用する場合は、おそらくニーズに最も適しているでしょう。
#define
const
const int
enum