namespace and enum?

Discussion in 'C++' started by Jamiil, Feb 4, 2006.

  1. Jamiil

    Jamiil Guest

    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
     
    Jamiil, Feb 4, 2006
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Feb 4, 2006
    #2
    1. Advertising

  3. Jamiil

    Jamiil Guest

    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
     
    Jamiil, Feb 4, 2006
    #3
  4. 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
     
    Victor Bazarov, Feb 4, 2006
    #4
  5. Jamiil

    Daniel T. Guest

    In article <>,
    "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
    > ....
    > };
    > }
    >
    > 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.
     
    Daniel T., Feb 5, 2006
    #5
  6. Jamiil

    Luke Meyers Guest

    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
     
    Luke Meyers, Feb 5, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    548
  2. Jerminia
    Replies:
    3
    Views:
    633
    Roedy Green
    Oct 7, 2005
  3. Ernst Murnleitner

    How to enum an enum?

    Ernst Murnleitner, Nov 12, 2003, in forum: C++
    Replies:
    5
    Views:
    469
    Rolf Magnus
    Nov 13, 2003
  4. mrhicks
    Replies:
    2
    Views:
    427
    Dave Thompson
    Jun 10, 2004
  5. Brian
    Replies:
    4
    Views:
    2,656
    Brian
    Feb 27, 2010
Loading...

Share This Page