On Nov 15, 4:35 pm, ajcrm125 <ajcrm...@gmail.comwrote:
I'm trying to utilize bitfields to make my file easier. But for some
reason, I can't assign a value to this structure. I'm sure I must be
missing something:
Several things, actually.
typedef unsigned short WORD;
WORD data;
union uVCTR {
WORD Ypos : 10; // Y position
WORD Ysign : 1; // Y position sign bit
WORD temp : 1; //
WORD opCode : 4; // 0..100 (8 bits)
} VCTR;
First, I'm not sure what bitfields are supposed to mean in a
union. I can't find anything offhand, but I would have assumed
that it was illegal. (There's a guarantee somewhere that all of
the elements of a union have the same address. Bitfields don't
have an address.)
Second, supposing you mean struct instead of union, you
mentioned files. Bitfield's define a purely internal format,
and can't be used when external formats are involved.
VCTR = data;
"error C2679: binary '=' : no operator defined which takes a right-
hand operand of type 'unsigned short' (or there is no acceptable
conversion)"
And finally, why should it work? On one side of the assignment,
you have a class type (uVCTR), on the other an unsigned short.
Two totally unrelated types.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34