Topic: SV: Enumerator declared in class scope


Author: "Niklas Pettersson" <npedt97@student.vxu.se>
Date: 2000/01/22
Raw View
It's only one minor error in the code discussed above (in my opinion)...
The line
    A::Color c = A::Color::RED;
should be
    A::Color c = A::RED;

This is perfectly legal since the enumeration Color is public in class A.
Even the
members of Color is accessable outside the class since they have the same
scope as the enumerationtype itself. In my opinition, enumerations is the
best way to create class constants.

This is an example that follows the latest standard

#include <iostream>

using namespace std;

class A
{
 public:

  enum Color { RED, GREEN, BLUE };

};

int main()
{
 A::Color c = A::RED;

   cout << c << endl;
}


Michael Kochetkov <mkochetk@trustworks.commm> skrev i
diskussionsgruppsmeddelandet:3883622d@newshost.elvis.ru...
>
> Hi, all,
> I found interesting thing (at least for me). MS compiler allows the
> following access to enumerator:
> class A {
> public:
>   enum Color { REG, GREEN, BLEU};
> };
>
> ....
> A::Color c = A::Color::RED;
>                             ^^^^^
>
> BG is not right, is he? :)
>
> With regards,
> Michael Kochetkov.
>
> P.S. ^^^^^ sign is under the <Color>.
>
>
>
>
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]
>


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]