C++函数覆盖的问题
#include <iostream>
using namespace std;
class Base
{
public:
virtual void g(int i = 10){
cout << i << endl;
};
};
class Derived: public Base
{
public:
void g(int i = 20){
cout << "Derived::g() " << i << endl;
};
};
int main() {
Base* pb = new Derived;
pb->g();
delete pb;
return 0;
}
输出结果:"Derived::g() " 10
请高手解释一下,i值为什么是10,而不是20呢?谢谢