Basically, if I don't do all objects get a copy of all the enum values?
ps: as always, references for your answer are always welcome...
Basically, if I don't do all objects get a copy of all the enum values?
ps: as always, references for your answer are always welcome...
You cannot declare a nested type (such as enum) static. Syntactically.
You can't, it doesn't make sense. Each instance doesn't store the values, they would store a value that happens to come from the enumerated values.
Enums don't hold all possible values. The various possible values only exist in the code during compile time. At run time, each instance of an enum is essentially an integral value.
With the enum keyword you are actually defining a type, not defining storage like a data member.
It's like defining an inner class, like this:
class X
{
private:
class InnerClass
{
...
};
};
The InnerClass definition is just a definition. It just defines the type within the context of the outer class X, so InnerClass can only be referred to as X::InnerClass. But it definitely doesn't take any space in the instances of class X.
Regarding the remark on enums: The enum values are actually integers, and these integers are used in the code where needed. Normally there is no central storage of all the enum values. The enum just defines a mapping between a token and a numerical value and everywhere the token is used in your code, the compiler replaces it with the numerical value.
enum {..}
s don't really take up any space in your program. Only objects declared as that enumerated type take up any space. Even then, it is unlikely to be more space than fits in a machine register (since they are comptaible with integer types).
The only place there will ever be any storage associated with all the enumerated names and values defined for the type is during compilation. At runtime, all that information is unnessecary (and thus is not there).