 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ivan Novick Guest
|
Posted: Sun Dec 24, 2006 1:29 am Post subject: enum point of declaration |
|
|
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 ] |
|
| Back to top |
|
 |
Greg Herlihy Guest
|
Posted: Tue Dec 26, 2006 6:47 pm Post subject: Re: enum point of declaration |
|
|
Ivan Novick wrote:
| Quote: | 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 ] |
|
| Back to top |
|
 |
Yechezkel Mett Guest
|
Posted: Wed Dec 27, 2006 5:21 am Post subject: Re: enum point of declaration |
|
|
Ivan Novick wrote:
| Quote: | 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 ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|