In my code, I typically use char variables in classes to flag particular properties of that class 1 bit at a time. What I am wondering is, if I use a public inheritance structure with an abstract class, and each derived class uses the variable cFlags1 in its own unique way (i.e. the bits do not mean the same thing), would it make more sense to have the cFlags1 variable declared in each class declaration separately or just once in the base class?
Code:
class Graphics
{
public:
virtual AbstractMe()=0;
private:
char cFlags1;
};
For the inherited class Sprite, a way that variable might be used is like this:
Code:
class Sprite : public Graphics
{
// cFlags1
// 0x01 - visible?
// 0x02 - animation initialized?
// 0x04 - scaled?
// 0x08 - framed?
// 0x10 - flash?
};
Whereas a Box might use the variable like this:
Code:
class Box : public Graphics
{
// cFlags1
// 0x01 - visible?
// 0x02 and 0x04
// two bits signify on screen position
};
Either way, I need a cFlags1 variable in each class, but the Sprite class is much more complex than the Box class, and does not have the same bitwise properties. Is it alright to keep the cFlags1 declaration in the base class as long as its properties are handled strictly in the derived classes?