我知道n = 2是来自B类,而2 << 3是16是来自D类,但是我不明白为什么会这样。
class B
{
public:
virtual int shift(int n = 2) const { return n << 2; }
};
class D
: public B
{
public:
D() {}
public:
int shift(int n = 3) const { return n << 3; }
};
int main()
{
const D d;
const B* b = &d;
std::cout << b->shift() << std::endl;
return 0;
}