C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

enum point of declaration

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Ivan Novick
Guest





PostPosted: Sun Dec 24, 2006 1:29 am    Post subject: enum point of declaration Reply with 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'

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





PostPosted: Tue Dec 26, 2006 6:47 pm    Post subject: Re: enum point of declaration Reply with quote



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





PostPosted: Wed Dec 27, 2006 5:21 am    Post subject: Re: enum point of declaration Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.