有人可以解释为什么以下代码的输出是B:2
?当没有调用x
num
如何获得A::print(int)
的值
#include <iostream>
class A
{
public:
void virtual print(int num = 2) {
std::cout << "A:" << num << std::endl;
}
};
class B : public A
{
public:
void virtual print(int x = 22) {
std::cout << "B:" << x << std::endl;
}
};
int main()
{
A *a = new B;
a->print();
delete a;
return 1;
}