Calling an overloaded function from a derived class
本问题已经有最佳答案,请猛点这里访问。
这里是C++新手。是否有方法从派生类中具有相同签名的相同函数名调用基类中的重载函数?在Smalltalk中,我可以使用"super"关键字。有C++的等价物吗?
1 2 3 4 5 6 7 8 9 | class MyBaseClass { void initialize() { doSomething(); } }; class MyDerivedClass : public MyBaseClass { void initialize() { super initialize(); // first, call MyBaseClass::initialize() doLocalInitialize(); // now initialize non-inherited members } |
谢谢,定额
你在评论中字面上说的是正确的语法:)
1 2 3 4 5 6 7 8 9 | class MyBaseClass { void initialize() { doSomething(); } }; class MyDerivedClass : public MyBaseClass { void initialize() { MyBaseClass::initialize(); // first, call MyBaseClass::initialize() doLocalInitialize(); // now initialize non-inherited members } |