It depends. If you are defining a single value, then you should use a constant. If you are defining multiple values to be used together, then you should use an enum. Enum is often used in a class declaration in place of a constant because some compilers do not allow you to set the value of the const inline. ie. you can't write this:
I recomend that you always use enums when possible.
Most compilers will not let you initialize a constant variable inside the class declaration.
However all C++ compilant compilers will let you set the enum value in the header.
By putting the value in the header, it makes your code less ambiguous.
The only draw back with the enum method, is that if you change the value, you have to recompile all source files referencing the header.
Where as using the const method, you only have to recompile the *.cpp file that contains the initialized variable.
Bookmarks