Topic: Enumerator declared in class scope
Author: "Gene Bushuyev" <gbush@my-deja.com>
Date: 2000/01/18 Raw View
"Michael Kochetkov" <mkochetk@trustworks.commm> wrote in message
news: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? :)
>
This is an error. A::Color is neither a class nor a namespace. But below is
the example that works:
class A {
public:
enum Color { RED, GREEN, BLUE};
static Color c;
};
A::Color A::c = RED;
A::Color b = A::c;
--
Gene Bushuyev
visit us at http://www.systemc.org
Entia non sunt multiplicanda praeter necessitatem
[ 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 ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/01/19 Raw View
In article <3883622d@newshost.elvis.ru>, Michael Kochetkov
<mkochetk@trustworks.commm> writes
>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;
> ^^^^^
Which is, of course, an error which will be detected as soon as you port
your code to another compiler. The error in itself may seem harmless
but it can damage the reputation of conforming compilers that do not
tolerate it.
Letting through a few 'harmless' coding errors is an excellent way of
persuading your less well informed (the majority?) customers that your
rivals' products are flaky.
>
>BG is not right, is he? :)
>
>With regards,
>Michael Kochetkov.
>
>P.S. ^^^^^ sign is under the <Color>.
Francis Glassborow Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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 ]
Author: "Gene Bushuyev" <gbush@my-deja.com>
Date: 2000/01/19 Raw View
"Huber Heinz" <Heinz.Huber@elbanet.co.at> wrote in message
news:3885BDBF.CE02D306@elbanet.co.at...
>
>
> Gene Bushuyev wrote:
[snip]
> > class A {
> > public:
> > enum Color { RED, GREEN, BLUE};
> > static Color c;
> > };
> > A::Color A::c = RED;
> > A::Color b = A::c;
>
> AFAIK this shouldn't compile either, since RED is not known outside A.
> Therefore this should be
> A::Color A::c = A::RED;
>
Not really. RED is considered to be in the scope of the class A in the
definition of A::c. One doesn't have to use a qualified-id with static
members, enumerators, and nested types. See 9.4 for explanations.
--
Gene Bushuyev
visit us at http://www.systemc.org
Entia non sunt multiplicanda praeter necessitatem
[ 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 ]
Author: Huber Heinz <Heinz.Huber@elbanet.co.at>
Date: 2000/01/20 Raw View
Gene Bushuyev wrote:
>
> "Michael Kochetkov" <mkochetk@trustworks.commm> wrote in message
> news: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? :)
> >
>
> This is an error. A::Color is neither a class nor a namespace. But below is
> the example that works:
> class A {
> public:
> enum Color { RED, GREEN, BLUE};
> static Color c;
> };
> A::Color A::c = RED;
> A::Color b = A::c;
AFAIK this shouldn't compile either, since RED is not known outside A.
Therefore this should be
A::Color A::c = A::RED;
Heinz
---
[ 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 ]
Author: "Michael Kochetkov" <mkochetk@trustworks.commm>
Date: 2000/01/17 Raw View
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 ]