By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

enum Conflicts

P: n/a
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
};
}

Sep 23 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
th**********@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
Sep 23 '06 #2

P: n/a
Would you be kind to show how the boolean operators work on these?
Would it be like Gender::male?
Jens Theisen wrote:
th**********@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
Sep 23 '06 #3

P: n/a
"th**********@gmail.com" <th**********@gmail.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_error("invalid enum");
}

Regards,

Jens
Sep 23 '06 #4

P: n/a
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
Sep 23 '06 #5

P: n/a
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;

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

--
Salu2
Sep 24 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.