构造函数中的C+虚拟函数
下面的示例为什么打印“0”,以及必须更改哪些内容才能像我所期望的那样打印“1”?
#include <iostream>struct base {
virtual const int value() const {
return 0;
}
base() {
std::cout << value() << std::endl;
}
virtual ~base() {}};struct derived : public base {
virtual const int value() const {
return 1;
}};int main(void) {
derived example;}慕哥6287543
侃侃无极
相关分类