473,698 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enum fails with using declaration

As I understand it, loaded statement, a using declaration should be all I
need to see an enum from within a namespace. The below code works fine with
class, struct, and union. What gives? As the code says, if I employ the
using directive, I'm ok.

/* built with Visual C++ 6, SP 5 */
namespace Traffic
{
enum Light { red, yellow, green };
}

int main( void )
{
/*using namespace Traffic; /* using directive. OK */
using Traffic::Light; /* using declaration. error C2065: 'red' :
undeclared identifier */

Light broken = red;
return broken;
}

Nov 13 '05 #1
3 3225
"Marshall Mills" <Mr************ ********@Yahoo. com> writes:
As I understand it, loaded statement, a using declaration should be all I
need to see an enum from within a namespace.


C doesn't have using declarations. Please don't ask C++
questions in comp.lang.c.
Nov 13 '05 #2
Marshall Mills wrote:
As I understand it, loaded statement, a using declaration should be all I
need to see an enum from within a namespace. The below code works fine
with
class, struct, and union. What gives?


Please keep comp.lang.c out of this one. Thanks. :-)

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #3
Marshall Mills wrote:
As I understand it, loaded statement, a using declaration should be all I
need to see an enum from within a namespace. The below code works fine with
class, struct, and union. What gives? As the code says, if I employ the
using directive, I'm ok.


You probably want to restrict your C++ questions to comp.lang.c++. When
you post to both that newsgroup and comp.lang.c, you really should have a
question which could be answered in either language. Those questions are
becoming rarer, with both C++ features not part of C and C features not
part of C++, as well as situations in which the answers are different --
either because the languages are different or because the usual idiom and
normal practice is different in the two languages.

In this case, there is no "using directive" or "using declaration" in C.
Namespace rules differ in the two languages, and named namespaces are not
part of C at all.

I have set followups to comp.lang.c++ only. Should you have a C question,
feel free to post that in comp.lang.c.

[C++ content follows, topical for one of the xposted newsgroups; please
ignore c.l.c]
Why not just use:

namespace Traffic
{
enum Light
{ red, yellow, green };
}

int main(void)
{

Traffic::Light broken = Traffic::red;
return broken;
}

--
Martin Ambuhl

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
37073
by: Alexander Grigoriev | last post by:
Not quite new version of GCC that I have to use, craps with the following code: enum E; enum E { e }; That is, it doesn't accept forward declaration of enum. C++ standard text doesn't explicitly say about enum's forward declaration, but one example shows it in 18.2.1, clause 4:
20
4842
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum EnumName FirstValue = 1 SecondValue = 2 ThirdValue = 3
4
642
by: Marshall Mills | last post by:
As I understand it, loaded statement, a using declaration should be all I need to see an enum from within a namespace. The below code works fine with class, struct, and union. What gives? As the code says, if I employ the using directive, I'm ok. /* built with Visual C++ 6, SP 5 */ namespace Traffic { enum Light { red, yellow, green }; }
4
3051
by: Chris | last post by:
I've lurked around long enough... Time to interract =) I'm trying to make sense of the following. I can't quite wrap my head around what this is actually doing: ------------- typedef enum { DOUBLE_LIST, INT_LIST } DATA_TYPE; typedef struct { DATA_TYPE type;
10
5810
by: James Brown | last post by:
I have the following enum declared: enum TOKEN { TOK_ID = 1000, TOK_NUMBER, TOK_STRING }; (it goes on and on like that) This is what I would like to do: TOKEN t1 = TOK_ID; // ok TOKEN t2 = 5; // compile error (cannot convert from
4
5732
by: marc.gibian | last post by:
I have been trying to improve the quality of my C# and ADO.NET coding. One of the books I've read strongly advises against using string values to address individual values in DataRow objects. This rings true to me after years of avoiding string lookups whenever possible. But, when I attempted to implement this recommendation I appear to run into casting issues. Thus: enum myFields { field1 = 0, field2 = 1
10
3897
by: Randy | last post by:
Hi, Can anyone point me to a complete, compilable example of Besser's ENUM++ mechanism? I downloaded it from CUJ and gave it a try but got errors just trying to compile the header enum.h. --Randy Yates
1
2456
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and installed the boost library. This is using gcc under FC3.
2
2118
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and installed the boost library. This is using gcc under FC3.
8
8542
by: benn | last post by:
Here's the setup... Defines.h file contains: enum DAY { monday, tueday }; DayFunctions.h contains prototype: void printIsMonday ( enum DAY currentDay); DayFunctions.c contains:
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.