473,756 Members | 3,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

namespace and enum?

Hey folks!
I have declared an enum type inside a name space
namespace jme{
enum hero_t{zorro, batmant, cat_woman, other};
class MyClass{
private: hero_t my_hero
.....
};
}

But the compiler complain saying:
somefile.hpp:26 : error: conflicting declaration 'zorro'
somefile.hpp:26 : error: 'jme::zorro' has a previous declaration as
`jme::hero_t
....

and the same error is produced for all the other members of hero_t?

What am I doing wrogn?

TIA

Feb 4 '06 #1
5 3097
Jamiil wrote:
Hey folks!
I have declared an enum type inside a name space
namespace jme{
enum hero_t{zorro, batmant, cat_woman, other};
class MyClass{
private: hero_t my_hero
....
};
}
I counted 7 lines total here (including the ellipsis).

But the compiler complain saying:
somefile.hpp:26 : error: conflicting declaration 'zorro'
somefile.hpp:26 : error: 'jme::zorro' has a previous declaration as
`jme::hero_t
Which one is line 26 and what happened with the other nineteen?
...

and the same error is produced for all the other members of hero_t?
Is that a question?

What am I doing wrogn?


You're not posting the code you're getting the error in. Read
the FAQ section 5.

V
--
Please remove capital As from my address when replying by mail
Feb 4 '06 #2
Hello Victor, thanks for your prompt response.
You are absolutely right; I am not posting the source code, just a
sample code.
It is company policy not to disclose any parts of the programs, but I
can provide you with an example that demonstrates the error. But, at
the same time, who in their right mind would want 828,675 lines of code
in the bandwidth. I could use a snip, which is something the company
does not want, but the snip will show the same data; all I have to do
is change the names of things.
Thanks Victor for all the help, "surely it would be very difficult to
solve problems without the help of programmers like yourself".
Victor Bazarov wrote:
Jamiil wrote:
Hey folks!
I have declared an enum type inside a name space
namespace jme{
enum hero_t{zorro, batmant, cat_woman, other};
class MyClass{
private: hero_t my_hero
....
};
}


I counted 7 lines total here (including the ellipsis).

But the compiler complain saying:
somefile.hpp:26 : error: conflicting declaration 'zorro'
somefile.hpp:26 : error: 'jme::zorro' has a previous declaration as
`jme::hero_t


Which one is line 26 and what happened with the other nineteen?
...

and the same error is produced for all the other members of hero_t?


Is that a question?

What am I doing wrogn?


You're not posting the code you're getting the error in. Read
the FAQ section 5.

V
--
Please remove capital As from my address when replying by mail


Feb 4 '06 #3
Jamiil wrote:
...
Don't top post.
Victor Bazarov wrote:
Jamiil wrote:
Hey folks!
I have declared an enum type inside a name space
namespace jme{
enum hero_t{zorro, batmant, cat_woman, other};
class MyClass{
private: hero_t my_hero
....
};
}
I counted 7 lines total here (including the ellipsis).

But the compiler complain saying:
somefile.hpp:26 : error: conflicting declaration 'zorro'
somefile.hpp:26 : error: 'jme::zorro' has a previous declaration as
`jme::hero_t


Which one is line 26 and what happened with the other nineteen?
...

and the same error is produced for all the other members of hero_t?


Is that a question?

What am I doing wrogn?


You're not posting the code you're getting the error in. Read
the FAQ section 5.


Hello Victor, thanks for your prompt response.
You are absolutely right; I am not posting the source code, just a
sample code.


No, it's not even sample code. Sample code would actually be suitable
to put in a file and pass to the compiler to demonstrate the error you
were asking about.
It is company policy not to disclose any parts of the programs, but I
can provide you with an example that demonstrates the error.
What stopped you the first time?
But, at
the same time, who in their right mind would want 828,675 lines of
code in the bandwidth.
Nobody. That's why the FAQ says what it says. Did you bother to read
it, as I suggested?
I could use a snip, which is something the
company does not want, but the snip will show the same data; all I
have to do is change the names of things.


It is up to you to remove all irrelevant pieces. Do that. Perhaps
while doing it you will discover what is wrong with your program...

V
--
Please remove capital As from my address when replying by mail
Feb 4 '06 #4
In article <11************ **********@g44g 2000cwa.googleg roups.com>,
"Jamiil" <ja******@netsc ape.net> wrote:
Hey folks!
I have declared an enum type inside a name space
namespace jme{
enum hero_t{zorro, batmant, cat_woman, other};
class MyClass{
private: hero_t my_hero
....
};
}

But the compiler complain saying:
somefile.hpp:26 : error: conflicting declaration 'zorro'
somefile.hpp:26 : error: 'jme::zorro' has a previous declaration as
`jme::hero_t
...

and the same error is produced for all the other members of hero_t?

What am I doing wrogn?


The problems I found in your code:
1) '....' is a parse error. I'm thinking it should be commented out.
2) 'hero_t my_hero' didn't have a semicolon after it, I fixed that.

The below compiles fine.

namespace jme {
enum hero_t {zorro, batmant, cat_woman, other};
class MyClass {
private:
hero_t my_hero;
//...
};
}

Now, what can I do to the above code to caluse the kind of errors you
are talking about? How about...

namespace jme {
enum hero_t {zorro, batmant, cat_woman, other};
enum hero_t {zorro, batmant, cat_woman, other};
}

The above seems to do something much like what you are complaining
about. I'd say your problem is multiple declarations in the same source
file.

Read up on include guards.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 5 '06 #5
Jamiil wrote:
You are absolutely right; I am not posting the source code, just a
sample code.
It is company policy not to disclose any parts of the programs,
Sigh... all together now... "post the smallest complete example that
demonstrates the problem."
but I
can provide you with an example that demonstrates the error.
Why didn't you?
But, at
the same time, who in their right mind would want 828,675 lines of code
in the bandwidth.
No one, obviously. Who in their right mind would think it would be
necessary? Post the relevant code, not every line of code you have
access to. Nothing you're experiencing is complex enough to require
nearly that much code to explain it.

Incidentally, leaking a precise SLOC number like this is probably just
the sort of technical information your company would rather not see
floating around the internet.
I could use a snip, which is something the company
does not want, but the snip will show the same data; all I have to do
is change the names of things.


It should be trivial to post a sufficiently simplified and abstract
example of the problem that no sane employer would object to. Perhaps
you're being overly literal with regard to company policy? Policies
like this are always conservatively worded, sometimes to excess (much
like a EULA) to cover the org's ass. Your job is to interpret the rule
in such a way that you can respect it and follow its intent, but not so
narrowly that it winds up inhibiting your job (contrary to its
presumable intent).

Luke

Feb 5 '06 #6

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

Similar topics

4
3825
by: marco_segurini | last post by:
Hi, the following test program shows a solution to a problem I have had. Now, this test program is compiled and linked by VS2003 and g++ while Comeau-on-line-compiler fails with this messages: "ComeauTest.c", line 21: error: constant "COuter::ID" is inaccessible int i = COuter::ID; ^
0
1052
by: Old Wolf | last post by:
My compiler chokes on the following code: namespace foo { typedef enum E { buz, baz } E; }; namespace bar { using foo::E; };
3
2321
by: balor | last post by:
Sometimes it is useful to assign class names to types that are primitives even if they add no more functionality, at the very least to be able to determine which constants apply to a type: typedef int Address; void test(Address address) { ... } const Address ADDRESS1 = 0xff, ADDRESS2 = 0x3f; Of course, this method is type unsafe since any int can be passed in but to the reader it is at least clear that ADDRESS1 and ADDRESS2 are
0
1184
by: Alf P. Steinbach | last post by:
Is there any way to get the "enabling" traits definitions textually closer to (ideally on the line below) the enums they refer to, in the code below? template< bool shouldBeTrue > struct StaticAssert_; template<> struct StaticAssert_<true> {}; template< typename T > struct EnumIncrementEnabled_{ enum{ yes = false }; };
3
2551
by: toton | last post by:
I have an enum in a namespace like, namespace client{ namespace ui{ enum InkEnum{ ID_INK_COLOR, ID_INK_WIDTH, }; class InkEventHandler{ ... };
13
18151
by: toton | last post by:
Hi, I have some enum (enumeration ) defined in some namespace, not inside class. How to use the enum constant's in some other namespace without using the whole namespace. To say in little detail, the enum is declared as, namespace test{ enum MyEnum{ VALUE1,VALUE2 };
2
2454
by: John Smith | last post by:
Hi All, (I first posted this question on the csharp.general but got no response, and since this NG is more active, so I repost it here) I have two enum definitions from two different namespaces: namespace ns1 { public enum e1{
1
1643
by: ThunderMusic | last post by:
Hi, I have many classes a user may need to call methods on my webservice. Some classes are "published" and some are not... I mean, when we do a Web reference from another project, we don't have access to some classes remotely... Is there something special these classes need so we can use them remotely? There's an example at the end of the post Here, Result is accessible, but ContactData is not... and there are others
4
2144
by: Hua.watson | last post by:
I want to add some declaration intio my namespace. But I do not have the right to modify proto header files. So I try namespace mynamespace{ #include "a.h" #include "b.h" }
0
9273
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
10032
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
9872
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
9841
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
9711
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8712
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
7244
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
5303
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.