C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem using enum with vector?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
BCC
Guest





PostPosted: Fri Oct 31, 2003 2:43 am    Post subject: Problem using enum with vector? Reply with quote



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?


Back to top
BCC
Guest





PostPosted: Fri Oct 31, 2003 4:02 am    Post subject: Re: Problem using enum with vector? Reply with quote



Quote:
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 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 :)



Back to top
Josephine Schafer
Guest





PostPosted: Fri Oct 31, 2003 4:03 am    Post subject: Re: Problem using enum with vector? Reply with quote




"BCC" <a@b.c> wrote

Quote:
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



Back to top
Chris Theis
Guest





PostPosted: Fri Oct 31, 2003 8:51 am    Post subject: Re: Problem using enum with vector? Reply with quote


"BCC" <a@b.c> wrote

Quote:
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 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.


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



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.