这段代码的输出是15,我真的不知道为什么.我认为它x=5在foo功能中使用,但我不知道为什么.谁能帮我 ?
#include <iostream>
#include <string>
using namespace std;
struct A
{
virtual int foo(int x = 5)
{
return x*2;
}
};
struct B : public A
{
int foo(int x = 10)
{
return x*3;
}
};
int main(int argc, char** argv)
{
A* a = new B;
cout << a->foo();
return 0;
}
Run Code Online (Sandbox Code Playgroud)