为什么以下示例打印"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;
}
Run Code Online (Sandbox Code Playgroud)