Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

enum Conflicts

32 views
Skip to first unread message

thetru...@gmail.com

unread,
Sep 23, 2006, 1:39:54 PM9/23/06
to
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

unread,
Sep 23, 2006, 2:43:41 PM9/23/06
to
thetru...@gmail.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

thetru...@gmail.com

unread,
Sep 23, 2006, 3:07:26 PM9/23/06
to
Would you be kind to show how the boolean operators work on these?
Would it be like Gender::male?

Jens Theisen

unread,
Sep 23, 2006, 3:50:43 PM9/23/06
to
"thetru...@gmail.com" <thetru...@gmail.com> writes:

> 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_error("invalid enum");
}

Regards,

Jens

Julián Albo

unread,
Sep 23, 2006, 4:07:01 PM9/23/06
to
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_error("invalid enum");
> }

Bisexuality error.

--
Salu2

thetru...@gmail.com

unread,
Sep 23, 2006, 8:29:39 PM9/23/06
to
Thanks guys. I put each of them into a namespace. So when I delcare
one I do

facebook::Gender::Gender name;
name = facebook::Gender::male;

0 new messages