 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
BCC Guest
|
Posted: Fri Oct 31, 2003 2:43 am Post subject: Problem using enum with vector? |
|
|
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
|
Posted: Fri Oct 31, 2003 4:02 am Post subject: Re: Problem using enum with vector? |
|
|
| 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
|
Posted: Fri Oct 31, 2003 4:03 am Post subject: Re: Problem using enum with vector? |
|
|
"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
|
Posted: Fri Oct 31, 2003 8:51 am Post subject: Re: Problem using enum with vector? |
|
|
"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 |
|
 |
|
|
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
|
|