You could use unions to convert structures to integers like this:
Code:
typedef union{
short asShort;
struct{
unsigned short L:4;
unsigned short B:4;
unsigned short R:4;
unsigned short F:4;
};
struct{
unsigned short W:4;
unsigned short S:4;
unsigned short E:4;
unsigned short N:4;
};
}mazeU;
This enables you to treat mazeU as a struct with members L, B, R, and F; as a struct with members W, S, E, and N; or a stort int.
That's for C; C++ could add some eligance to that. For example:
You could allow casting to short like this:
Code:
class mazeD{
protected:
unsigned short L:4;
unsigned short B:4;
unsigned short R:4;
unsigned short F:4;
public:
operator short() const {return ((short)F<<12)+((short)R<<8)+((short)b<<4)+L}
};
Further more, you can overload the bitwise operators themselves like this:
Code:
class mazeD{
protected:
unsigned short L:4;
unsigned short B:4;
unsigned short R:4;
unsigned short F:4;
public:
mazeD();//defult constructor
mazeD(mazeD&);//copy constructor
friend const mazeD operator^ (const mazeD&, const mazeD&);
};
const mazeD operator^ (mazeD Obj1, const mazeD& Obj2)
{
Obj1.L^=Obj2.L
Obj1.B^=Obj2.B
Obj1.R^=Obj2.R
Obj1.F^=Obj2.F
return Obj1;
}
I'm a little confuse about what you're trying to do, however.