有如下程序: #include using namespace std; class Instrument { public: virtual void Display()=0; }; class Piano : public Instrument {

admin2021-05-06  23

问题 有如下程序:
#include
using namespace std;
class Instrument {
public:
virtual void Display()=0;
};
class Piano : public Instrument {
public:
void Display() { /*函数体略*/ }
};
int main() {
Instrument s;
Instrument *p=0;
//… ;
return 0;
}
下列叙述中正确的是(    )。

选项 A、语句"Insturment *p=0;"编译时出错
B、语句"Instrument s;"编译时出错
C、类Piano中的Display函数不是虚函数
D、类Instrument是一个虚基类

答案B

解析 本题考查纯虚函数和抽象类,纯虚函数是在声明虚函数时被"初始化"为0的函数,包含纯虚函数的类为抽象类,抽象类不能被实例化,所以语句"Instrument s;"在编译时出错。
转载请注明原文地址:https://kaotiyun.com/show/wPfp777K
0

最新回复(0)