Problem using enum with vector?

B

BCC

I have a simple container class with an enum:

class MyObject {
typedef enum {
etype1,
etype2
} EType;
};

In another class I have a vector:
std::vector<MyObject::EType> type_vec;

Compiling works okay up to this point, but I need a vector of my enum types.
If I try to add one:

type_vec.push_back(MyObject::etype1);

I get a compiler error C2666 "etc etc" 2 overloads have similar conversions.

I use this enum in many places without a problem, just creating and using a
vector of them seems to be a problem.

What am I doing wrong?
 
B

BCC

Which compiler are you using?
This code works fine on both Comeau online as well as VC++ 7.

#include <vector>
class MyObject {
public:
typedef enum {
etype1,
etype2
} EType;
};
std::vector<MyObject::EType> type_vec;
int main ()
{
type_vec.push_back(MyObject::etype1);
type_vec.push_back(MyObject::etype2);
}

HTH,
J.Schafer

VC++ 7.... hmmm, something funky must be going on. But I cannot for the
life of me figure it out.

Thanks though, at least now I know it -should- compile :)
 
J

Josephine Schafer

BCC said:
I have a simple container class with an enum:

class MyObject {
typedef enum {
etype1,
etype2
} EType;
};

In another class I have a vector:
std::vector<MyObject::EType> type_vec;

Compiling works okay up to this point, but I need a vector of my enum types.
If I try to add one:

type_vec.push_back(MyObject::etype1);

I get a compiler error C2666 "etc etc" 2 overloads have similar conversions.

I use this enum in many places without a problem, just creating and using a
vector of them seems to be a problem.

What am I doing wrong?

Which compiler are you using?
This code works fine on both Comeau online as well as VC++ 7.

#include <vector>
class MyObject {
public:
typedef enum {
etype1,
etype2
} EType;
};
std::vector<MyObject::EType> type_vec;
int main ()
{
type_vec.push_back(MyObject::etype1);
type_vec.push_back(MyObject::etype2);
}

HTH,
J.Schafer
 
C

Chris Theis

BCC said:
VC++ 7.... hmmm, something funky must be going on. But I cannot for the
life of me figure it out.

Seems like you have a problem somewhere else 'cause this code also compiles
(as it should IMHO) under VC++ 6 SP5. Probably you can destil the code that
causes trouble and post it.

Chris
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top