C++遗传问题7

null

#include<iostream>
using namespace std;
class Base
{
public :
void show()
{
cout<< " In Base " ;
}
};
class Derived: public Base
{
public :
int x;
void show()
{
cout<< "In Derived " ;
}
Derived()
{
x = 10;
}
};
int main( void )
{
Base *bp, b;
Derived d;
bp = &d;
bp->show();
cout << bp->x;
return 0;
}


(A) “bp->show()行中的编译器错误” (B) “cout (C) 在10垒 (D) 在第10页 答复: (B) 说明: 基类指针可以指向派生类对象,但我们只能使用基类指针访问基类成员或虚拟函数,因为当派生类对象被分配给基类对象时,就会发生对象切片。派生类对象的附加属性被切掉,形成基类对象。 这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享