I can't understand what's going there.
Using Visual Studio 2008, I've defined an enum like this:
enum MyType{
A,
B,
C
};
Then I use it to initialize a member variable:
class MyClass
{
private:
bool bit_;
uint16 num_;
MyType member_;
public:
MyClass(MyType value){
member_ = value; // This the assignment which fails
} // Here, there's a breakpoint to query member_ value
};
MyClass instance = new MyClass();
I'm using Debug configuration, so no optimization can fool me when reading
a variable. At a breakpoint just after the assignment, the debuger shows the value of member_ as member_ = C
.
It could be a debugger whatch refresh issue but, inside a method it evaluates true when checking:
if(member_ == C){
// ??
}
And also, assigning to the other values gives strange numbers, e.g. doing member_ = B
gives member_ = 258
when ferching it.
Can you tell me what's wrong? Thanks in advance.
EDIT #1
I've noted a funny effect which explains why after assigning member_ = A
the expression member_ == C
evaluates to true
for the enum with the default values:
For the enum
enum MyType{ A, B, C}; // equivalent to enum MyType{ A = 0, B = 1, C = 2};
I get
MyType a = A; // but when fetching a the value is 2 (0x0002) thats the map for C!
MyType b = B; // but when fetching a the value is 258 (0x0102)
MyType c = C; // but when fetching a the value is 514 (0x0202)
But if I make
enum MyType{ A = 5, B = 6, C = 7};
I get
MyType a = A; // but when fetching a the value is 1282 (0x0502)
MyType b = B; // but when fetching a the value is 1538 (0x0602)
MyType c = C; // but when fetching a the value is 1794 (0x0702)
So, when assigning that #?!^% enum, the rule seems to be, shift 8 bits and add 2.
It sounds like compiler issues.
Btw, making the type of member_
to be int
instead MyType
doesn't changes nothing.
EDIT #2
Added two more members to the class, which are the real cause of the problem. I'll post the
answer as soon as the time restriction vanishes (8h from the posting of the question).