What\'s the difference between using a define statement and an enum statement in C/C++ (and is there any difference when using them with either C or C++)?
For exampl
Enums are generally prefered over #define wherever it makes sense to use an enum:
enums value ("openType: OpenExisting", rather than "openType: 2"#defineition.The biggest difference is that you can use enums as types:
// Yeah, dumb example
enum OpenType {
OpenExisting,
OpenOrCreate,
Truncate
};
void OpenFile(const char* filename, OpenType openType, int bufferSize);
This gives you type-checking of parameters (you can't mix up openType and bufferSize as easily), and makes it easy to find what values are valid, making your interfaces much easier to use. Some IDEs can even give you intellisense code completion!