namespace and enum?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jamiil

    #1

    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

  • Victor Bazarov

    #2
    Re: namespace and enum?

    Jamiil wrote:[color=blue]
    > 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
    > ....
    > };
    > }[/color]

    I counted 7 lines total here (including the ellipsis).
    [color=blue]
    >
    > 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[/color]

    Which one is line 26 and what happened with the other nineteen?
    [color=blue]
    > ...
    >
    > and the same error is produced for all the other members of hero_t?[/color]

    Is that a question?
    [color=blue]
    >
    > What am I doing wrogn?[/color]

    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


    Comment

    • Jamiil

      #3
      Re: namespace and enum?

      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:[color=blue]
      > Jamiil wrote:[color=green]
      > > 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
      > > ....
      > > };
      > > }[/color]
      >
      > I counted 7 lines total here (including the ellipsis).
      >[color=green]
      > >
      > > 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[/color]
      >
      > Which one is line 26 and what happened with the other nineteen?
      >[color=green]
      > > ...
      > >
      > > and the same error is produced for all the other members of hero_t?[/color]
      >
      > Is that a question?
      >[color=green]
      > >
      > > What am I doing wrogn?[/color]
      >
      > 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[/color]

      Comment

      • Victor Bazarov

        #4
        Re: namespace and enum?

        Jamiil wrote:[color=blue]
        > ...[/color]

        Don't top post.
        [color=blue]
        > Victor Bazarov wrote:[color=green]
        >> Jamiil wrote:[color=darkred]
        >>> 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
        >>> ....
        >>> };
        >>> }[/color]
        >>
        >> I counted 7 lines total here (including the ellipsis).
        >>[color=darkred]
        >>>
        >>> 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[/color]
        >>
        >> Which one is line 26 and what happened with the other nineteen?
        >>[color=darkred]
        >>> ...
        >>>
        >>> and the same error is produced for all the other members of hero_t?[/color]
        >>
        >> Is that a question?
        >>[color=darkred]
        >>>
        >>> What am I doing wrogn?[/color]
        >>
        >> You're not posting the code you're getting the error in. Read
        >> the FAQ section 5.[/color]
        >
        > Hello Victor, thanks for your prompt response.
        > You are absolutely right; I am not posting the source code, just a
        > sample code.[/color]

        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.
        [color=blue]
        > It is company policy not to disclose any parts of the programs, but I
        > can provide you with an example that demonstrates the error.[/color]

        What stopped you the first time?
        [color=blue]
        > But, at
        > the same time, who in their right mind would want 828,675 lines of
        > code in the bandwidth.[/color]

        Nobody. That's why the FAQ says what it says. Did you bother to read
        it, as I suggested?
        [color=blue]
        > 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.[/color]

        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


        Comment

        • Daniel T.

          #5
          Re: namespace and enum?

          In article <1139026033.543 591.298670@g44g 2000cwa.googleg roups.com>,
          "Jamiil" <jalqadir@netsc ape.net> wrote:
          [color=blue]
          > 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?[/color]

          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.

          Comment

          • Luke Meyers

            #6
            Re: namespace and enum?

            Jamiil wrote:[color=blue]
            > 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,[/color]

            Sigh... all together now... "post the smallest complete example that
            demonstrates the problem."
            [color=blue]
            > but I
            > can provide you with an example that demonstrates the error.[/color]

            Why didn't you?
            [color=blue]
            > But, at
            > the same time, who in their right mind would want 828,675 lines of code
            > in the bandwidth.[/color]

            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.
            [color=blue]
            > 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.[/color]

            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

            Comment

            Working...