In C++, if we have some virtual function within some base class(say Base), we'd like to override this virtual function, we will have to declare this virtual function again to make it work even compile in our derived classes.
class Base {
public:
virtual void virtualFunction();
static int s_whatSoEver[];
private:
void _privateFunction();
}
class Derived {
public:
virtual void virtualFunction();
}
Wasn't this stupid since if we'd like change the virtual function prototype, we'd have to change every declaration of the derived-s?
Also, why is it necessary to declare some protected or private function within the header file, since header file is used for public interface definition, and the user who makes use of this interface would never need to care about them at all? Maybe we can just directly implement & declare the private or protected function in the .cpp file just like Objective-C.
C++ doesn't have static initializer neither, what if we want to initialize some static class variable we'd have to make a class for this:
class BaseStaticVariableInitializer {
public:
BaseStaticVariableInitializer() {
Base::s_whatSoEver = new int[20];
for (int i = 0; i < 20; i++) {
s_whatSoEver[i] = xxx;
}
}
~BaseStaticVariableInitializer() {
delete [] Base::s_whatSoEver;
}
}
and initialize a static class constant for it specifically:
static BaseStaticVariableInitializer s_baseStaticVariableInitializer;
Sorry for my being ignorant, but what is your right way to write your c++ codes to fit well with DRY?