I am trying to create several classes, all of which are derived classes from an abstract class (let's call it) BaseClass. In BaseClass, I want to work with static variables (arrays) declared in derived classes. Is there a smart way in C ++ so that the compiler knows that a static variable will be declared in the class that received the top class? Or should I, for example, in the constructor of derived classes pass a reference to a static variable on the construction of the base class? This is my idea:
class BaseClass
{
std::vector<float> &vector;
public:
BaseClass(std::vector<float> &dVector):vector(dVector){};
void vectorOperation()
{
vector.doSomething();
}
...
}
class DerivedClass : public BaseClass
{
static std::vector<float> sVector;
DerivedClass():BaseClass(sVector){};
...
}
Is my decision right? Is there a better way to do this?
Rames