enum Conflicts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thetrueaplus@gmail.com

    #1

    enum Conflicts

    Hey.

    I'm trying to make a couple of enums work, however mingW isn't
    compiling it because it says the previous declaration of none
    conflicts. is there a way to solve this?

    namespace Namespace
    {
    enum Gender // m or f
    {
    none = 0,
    male = 1 << 0,
    female = 1 << 1
    };

    enum LookingFor
    {
    none = 0,
    friendship = 1 << 0,
    dating = 1 << 1,
    relationship = 1 << 2,
    randomPlay = 1 << 3,
    whateverICanGet = 1 << 4
    };
    }

  • Jens Theisen

    #2
    Re: enum Conflicts

    thetrueaplus@gm ail.com writes:
    I'm trying to make a couple of enums work, however mingW isn't
    compiling it because it says the previous declaration of none
    conflicts. is there a way to solve this?
    There is a plethora of ways dealing with enums, and unfortunately no
    standard way everyone agrees upon.

    Two popular ways are wrapping each enum in a class or namespace of
    it's own:

    namespace Gender
    {
    enum enum_t { ... };
    }

    or

    class Gender
    {
    enum enum_t { ... };
    };

    With both approaches, you can have functions like toString that are
    found by ADL.

    I'd suggest you do something based on one of these approaches.

    Regards,

    Jens

    Comment

    • thetrueaplus@gmail.com

      #3
      Re: enum Conflicts

      Would you be kind to show how the boolean operators work on these?
      Would it be like Gender::male?
      Jens Theisen wrote:
      thetrueaplus@gm ail.com writes:
      >
      I'm trying to make a couple of enums work, however mingW isn't
      compiling it because it says the previous declaration of none
      conflicts. is there a way to solve this?
      >
      There is a plethora of ways dealing with enums, and unfortunately no
      standard way everyone agrees upon.
      >
      Two popular ways are wrapping each enum in a class or namespace of
      it's own:
      >
      namespace Gender
      {
      enum enum_t { ... };
      }
      >
      or
      >
      class Gender
      {
      enum enum_t { ... };
      };
      >
      With both approaches, you can have functions like toString that are
      found by ADL.
      >
      I'd suggest you do something based on one of these approaches.
      >
      Regards,
      >
      Jens

      Comment

      • Jens Theisen

        #4
        Re: enum Conflicts

        "thetrueaplus@g mail.com" <thetrueaplus@g mail.comwrites:
        Would you be kind to show how the boolean operators work on these?
        Would it be like Gender::male?
        I'm not sure what you mean by boolean operators.

        Gender::male would be a way to refer to an enumerator, eg.

        std::string toString(Gender ::enum_t e)
        {
        switch(e)
        {
        case Gender::male: return "male";
        case Gender::female: return "male";
        }

        throw std::runtime_er ror("invalid enum");
        }

        Regards,

        Jens

        Comment

        • Julián Albo

          #5
          Re: enum Conflicts

          Jens Theisen wrote:
          std::string toString(Gender ::enum_t e)
          {
          switch(e)
          {
          case Gender::male: return "male";
          case Gender::female: return "male";
          }
          >
          throw std::runtime_er ror("invalid enum");
          }
          Bisexuality error.

          --
          Salu2

          Comment

          • thetrueaplus@gmail.com

            #6
            Re: enum Conflicts

            Thanks guys. I put each of them into a namespace. So when I delcare
            one I do

            facebook::Gende r::Gender name;
            name = facebook::Gende r::male;

            Julián Albo wrote:
            Jens Theisen wrote:
            >
            std::string toString(Gender ::enum_t e)
            {
            switch(e)
            {
            case Gender::male: return "male";
            case Gender::female: return "male";
            }

            throw std::runtime_er ror("invalid enum");
            }
            Bisexuality error.

            --
            Salu2

            Comment

            Working...