问题详情

答题翼 > 问答 > 计算机类考试 > 正文
目录: 标题| 题干| 答案| 搜索| 相关

有如下程序: include<iostream> using namespace std; class Pet{ char name[10]; public: Pet(c


有如下程序:

include<iostream>

using namespace std;

class Pet{

char name[10];

public:

Pet(char*name){strcpy(this->name,name);}

const char*getName()const {return name;}

virtual void call()const=0;

};

class Dog:public Pet{

public:

Dog(char*name):Pet(name){}

void call()const{cout<<"汪汪叫":}

};

class Cat:public Pet{

public:

Cat(char*name):Pet(name){}

void call()const{cout<<"喵喵叫";}

};

int main(){

Pet*pet1=new Dog("哈克"),*pet2=new Cat("吉米");

cout<<pet1->getName();pet1->call();cout<<end1;

cout<<pet2->getName();pet2->call();cout<<end1;

return 0;

}

程序的输出结果是______。

请帮忙给出正确答案和分析,谢谢!

参考答案
您可能感兴趣的试题