This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++0x strongly typed enums


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jay I. wrote:
> as far as i know things inside enum are placed in the same scope where
> you put enum itself. this example compiles fine:
>
> enum{
>  CONST_1=1, CONST_2=2 // global scope
> };
>
> int main(){
>   int x=CONST_1+CONST_2;
>   return 0;
> }

For traditional enums, yes, but the new strongly typed enums introduced
in C++0x, denoted by 'enum class', have their own scope and the members
should not be accessible directly from the parent scope.

> i use enums with structures like this:
>
> struct options{
>   enum{
>     opt_1,opt_2,opt_3
>   };
> };
>
> ...
>
> int x=options::opt_1+options::opt_2;

This is actually one of the goals of the new enums, to make this
unnecessary.

> regards,
> jay

Chris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknqY1IACgkQ6iqRtkAADZhV3ACZAX9SGXRWe9l8Kijvg0Pn9cwx
65kAnikcW0QZFWwoQIuVJOu6YMsReUzG
=oVZV
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]