Topic: enum point of declaration


Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Tue, 26 Dec 2006 12:47:31 CST
Raw View
Ivan Novick wrote:
> Hi,
>
> 3.3.1/3 has an example which does not compile on gcc 4.1.1.
>
> Is it meant to compile?
>
> const int x = 12;
> enum { x = x };
> int main(int argc, char** argv)
> {
>   return 0;
> }
>
> test.cpp:4: error: 'x' redeclared as different kind of symbol
> test.cpp:3: error: previous declaration of 'const int x'

No, your program should not compile since both "x"'s are declared
within the same scope. In the actual example, the enum declaration has
local scope (hence the surrounding brackets).

A comparable example would be:

    const int x = 12;

    int main()
    {
        enum { x = x };
    }

Greg

---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]





Author: yechezkel@emailaccount.com (Yechezkel Mett)
Date: Tue, 26 Dec 2006 23:21:53 GMT
Raw View
Ivan Novick wrote:
> Hi,
>
> 3.3.1/3 has an example which does not compile on gcc 4.1.1.
>
> Is it meant to compile?
>
> const int x = 12;
> enum { x = x };
> int main(int argc, char** argv)
> {
>   return 0;
> }

The enum is supposed to be in a nested scope.
Try the following:

int main(int argc, char** argv)
{
   const int x = 12;
   { enum { x = x }; }
   return 0;
}

Note the braces round the enum declaration.

Yechezkel Mett

---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Ivan Novick" <ivan@0x4849.net>
Date: Sat, 23 Dec 2006 19:29:15 CST
Raw View
Hi,

3.3.1/3 has an example which does not compile on gcc 4.1.1.

Is it meant to compile?

const int x = 12;
enum { x = x };
int main(int argc, char** argv)
{
  return 0;
}

test.cpp:4: error: 'x' redeclared as different kind of symbol
test.cpp:3: error: previous declaration of 'const int x'

Thanks,
---
Ivan
http://www.0x4849.net

---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]