<分区>
Possible Duplicate:
Calling virtual method in base class constructor
Calling virtual functions inside constructors
如何从 C++ 中的构造函数调用 protected 虚方法?
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"