Non riesco a capire cosa sta succedendo lì. Usando Visual Studio 2008, ho definito un enum come questo:
enum MyType{
A,
B,
C
};
Quindi lo uso per inizializzare una variabile membro:
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 ();
Sto usando la configurazione del debug, quindi nessuna ottimizzazione può ingannarmi quando leggo una variabile. A un punto di interruzione subito dopo l'incarico, il debugger mostra il valore di membro_ come member_ = C
.
Potrebbe essere un problema di aggiornamento Whatch Debugger ma, all'interno di un metodo, valuta il vero durante il controllo:
if(member_ == C){
// ??
}
E inoltre, l'assegnazione agli altri valori fornisce numeri strani, ad es. member_ = B
dà member_ = 258
Quando lo si fermò. Puoi dirmi cosa c'è che non va? Grazie in anticipo.
EDIT #1
Ho notato un effetto divertente che spiega perché dopo l'assegnazione member_ = A
l'espressione member_ == C
valuta a true
Per l'Enum con i valori predefiniti:
Per l'enum
enum MyType{ A, B, C}; // equivalent to enum MyType{ A = 0, B = 1, C = 2};
ottengo
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)
Ma se faccio
enum MyType{ A = 5, B = 6, C = 7};
ottengo
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)
Quindi, quando si assegna quel #?!^% Enum, la regola sembra essere, sposta 8 bit e aggiungi 2. Sembra problemi di compilatore.
Btw, creando il tipo di member_
essere int
invece MyType
Non cambia nulla.
EDIT #2Aggiunti altri due membri alla classe, che sono la vera causa del problema. Pubblicherò la risposta non appena la limitazione del tempo svanisce (8 ore dalla pubblicazione della domanda).