(32 )有如下程序#include<iostream>using namespace std;class Publication{ // 出版物类
(32 )有如下程序
#include<iostream>
using namespace std;
class Publication{ // 出版物类
char name[30];
public:
Publication(char *name=" 未知名称 "){
strcpy(this->name,name);
}
const char * getName()const{ return name; }
virtual const char * getType()const{ return " 未知类型 ";}
};
class Book: public Publication{ // 书类
public:
Book(char *name): Publication(name){}
virtual const char * getType()const{ return " 书 " ; }
};
void showPublication(Publication &p){
cout<<p.getType()<<":"<<p.getName()<<endl;
}
int main(){
Book book(" 精彩人生 ");
showPublication(book);
return 0;
}
运行时的输出结果是
A )未知类型:未知名称
B )未知类型:精彩人生
C )书:未知名称
D )书:精彩人生
![](https://lstatic.shangxueba.com/sxbcn/h5/images/tips_org.png)