请问为什么去掉标记出来的const之后输出就成了0 而不是0,2 谢谢#includeusing namespace std;class Base{protected:int x;public:Base(int b=0): x(b) { }virtual void display() const {cout << x << endl;}};class Derived: public Base{int y;public:Derived(int d=0): y(d) { }void display() _ const_ {cout << x << "," << y << endl;}};int main(){Derived d(2);Base *p = &d;p->display();return 0;}
1 回答
- 1 回答
- 0 关注
- 1004 浏览
添加回答
举报
0/150
提交
取消