#include<iostream> using namespace std; class Base public: virtual void Show( )cout<<'B';; ,; class Derived:public Base 1 public: void Show( ) cout< <'D';- ,; int main( ) 1 Base *pl=new Derived; Derived *p2=new Derived; p1->Show0; p2->Show0; delete p1; delete p2; return 0; } 运行这个程序的输出结果是_
时间: 2024-01-18 14:05:07 浏览: 92
#include_iostream.h_
4星 · 用户满意度95%
这个程序存在语法错误,无法通过编译。具体地说,class Base的定义缺少了一个左花括号,应该修改为class Base{。同时,class Derived的定义也缺少了一个左花括号,应该修改为class Derived:public Base{。修改后的程序如下:
```c++
#include<iostream>
using namespace std;
class Base {
public:
virtual void Show() {
cout << 'B';
}
};
class Derived:public Base {
public:
void Show() {
cout << 'D';
}
};
int main() {
Base *p1 = new Derived;
Derived *p2 = new Derived;
p1->Show();
p2->Show();
delete p1;
delete p2;
return 0;
}
```
运行这个程序的输出结果是:
```
D
D
```
阅读全文