namespace and enum?

J

Jamiil

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
 
V

Victor Bazarov

Jamiil said:
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
 
J

Jamiil

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".
 
V

Victor Bazarov

Jamiil said:

Don't top post.
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
 
D

Daniel T.

"Jamiil said:
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.
 
L

Luke Meyers

Jamiil said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top