Is there anyway I can modify this code example
#include <stdlib.h>
#include <iostream>
class Base {
public:
Base() {
if(!m_initialized) {
static_constructor();
m_initialized = true;
}
}
protected:
virtual void static_constructor() {
std::cout << "Base::static_constructor()\n";
}
private:
static bool m_initialized;
};
bool Base::m_initialized = false;
class Derived : public Base {
void static_constructor() {
std::cout << "Derived::static_constructor()\n";
}
};
int main(int argc, char** argv) {
Derived d;
return(EXIT_SUCCESS);
}
So that Derived::static_constructor()
gets called instead of the Base's? I want to initialize a bunch of static variables, and the most logical place to do it is somewhere in the class.