Could someone please explain Enumerated Constants to me?
I dont understand them...thanks.
Printable View
Could someone please explain Enumerated Constants to me?
I dont understand them...thanks.
Another use for enumerations is within class scope.
for instance
Got this from c++ primer plus 3rd editionCode:class Blueprint
{
private:
const int Len=30; // error declaring a constant with class scope is an error because no object yet exists, until you create an object there is no place for the compiler to store a value.
instead:
class Blueprint
{
private:
enum {Len=30};//class specific constant does not create a class data member
However that's abuse of enums. The correct way to do a class-scoped constant is to make it static:
Code:class HasConstant
{
public:
static const int THE_CONSTANT;
};
// Implementation file:
const int HasConstant::THE_CONSTANT = 234;
Ahh things you learn from people and not from books thanks. (Although books are written by people lol)