Originally Posted by
MishaMish
I tried many things, but when calling a function from a base class it's calling the base's class's implementation ONLY, without calling the derived implementation first...
You could call the derived method inside the derived constructor, which would mean the base method happens first. If you must have the derived method fire first, you'll have to remove "initConfig" from both constructors and call it manually, calling the base method inside the derived one.
Code:
#include <iostream>
class One {
public:
One (int val) : x(val) { }
void initConfig () {
x += 2;
}
int x;
};
class Two : public One {
public:
Two (int val) : One(val) { }
void initConfig () {
x = x*x;
One::initConfig();
}
};
using namespace std;
int main(void) {
Two eg(5);
eg.initConfig();
cout << eg.x << endl;
return 0;
}