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…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
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.