Möglichen Duplizieren Aufruf:
Calling virtual method in base class constructor
Calling virtual functions inside constructorseine geschützte virtuelle Methode in C++
Wie kann ich eine geschützte virtuelle Methode von einem Konstruktor in C++ anrufen?
class Foo
{
Foo(){
printStuff(); // have also tried this->printStuff()
}
protected:
virtual void printStuff() {}
}
class ExtendedFoo : public Foo {
protected:
virtual void printStuff() { cout << "Stuff" << endl;}
}
...
ExtendedFoo exFoo; // should print "Stuff"
siehe http://stackoverflow.com/questions/962132/calling-virtual-functions-inside-constructors auch –