I'm a bit of a n00b when it comes to class deriving, so bear with me in this problem.
What if I want a class called sprite like this:
1 2 3 4 5
|
//Not necessarily perfect, I'm tired and can't test. Please excuse syntax errors
class sprite{
public:
void tick()=0;
};
|
Than, derived from sprite, I have many (50 plus) classes like:
1 2 3 4 5 6 7 8 9 10 11
|
class mover: public sprite{
public:
void tick(){ /*Blah*/ };
int number1;
};
class enemy: public sprite{
public:
void tick(){ /*Blah*/ };
int number2;
};
|
Now, this is all fine so far. The problem I'm facing involves a vector of "sprite"s.
|
vector<sprite> spriteVector;
|
Now, say that I have some "mover"s and some "enemy"s in the spriteVector. I could access their tick() by saying
but what if I need to access number1 or number2? Knowing if the variable exists in that certain class is not a problem in this case (scenario related) but I cannot access number1 / number2 without first defining them in sprite. Unfortunately, I feel that sprite would be flooded with values, causing all derived classes to have "junk" values they would never need, and use extra memory for no reason (in mass cases).
So, is it possible to access derived class variables that are not defined in the parent from a list based on the parent class?
Please explain in specific detail any answer please, I'm really lost (have been for a while)