構造函數(shù)中的C+虛擬函數(shù)下面的示例為什么打印“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;}
- 3 回答
- 0 關注
- 414 瀏覽
添加回答
舉報
0/150
提交
取消