This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C++0x strongly typed enums
- From: Chris Spencer <spencercw at googlemail dot com>
- To: "Jay I." <jay dot 27182818 at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 19 Apr 2009 00:33:50 +0100
- Subject: Re: C++0x strongly typed enums
- References: <49EA006D.70608@googlemail.com> <1240094637.18278.12.camel@jay>
-----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-----