代码+结果,不做解释 当然,对于python没有virtual function一说,估计当作对比一个例子看看吧。 #include <iostream> using namespace std; class base { public: virtual void foo() { cout << "base" << endl; } base() { foo() ;} }; class derive: public base { public: derive() { foo(); } virtual void foo() { cout << "derive" << endl; } }; int main() { derive d; return 0; } 结果: base derive class base(object): def __init__( self ): self.foo() def foo( self ): print "base" class derive( base ): def __init__( self ): super( derive , self ).__init__() self.foo() def foo( self ): print "derive" d = derive() 结果: derive derive