下面程序输出结果为: Display1() in BaseClass is called! Display1() in DerivedClass is called! Display2() in BaseClass is called! Display2() in BaseClass is called! 请将程序填写完整 #include <iostream> using namespace std; class BaseClass { public: (1) {cout<<"Display1() in BaseClass is called!"<<endl;} (2) {cout<<"Display2() in BaseClass is called!"<<endl;} }; class DerivedClass:public BaseClass { public: void Display1(){cout<<"Display1() in DerivedClass is called!"<<endl;} void Display2(){cout<<"Display2() in DerivedClass is called!"<<endl;} }; void fun1( (3) ) { p->Display1(); } void fun2(BaseClass &rb) { rb.Display2(); } int main() { BaseClass b; DerivedClass d; fun1(&b); fun1(&d); fun2(b); fun2(d); return 0; }
时间: 2024-04-01 13:33:38 浏览: 134
170: Warning: (1681, ‘Integer display width is deprecated and will be removed in a future release.’)
#include <iostream>
using namespace std;
class BaseClass {
public:
void Display1() {cout<<"Display1() in BaseClass is called!"<<endl;}
void Display2() {cout<<"Display2() in BaseClass is called!"<<endl;}
};
class DerivedClass:public BaseClass {
public:
void Display1() {cout<<"Display1() in DerivedClass is called!"<<endl;}
void Display2() {cout<<"Display2() in DerivedClass is called!"<<endl;}
};
void fun1(BaseClass *p) {
p->Display1();
}
void fun2(BaseClass &rb) {
rb.Display2();
}
int main() {
BaseClass b;
DerivedClass d;
fun1(&b);
fun1(&d);
fun2(b);
fun2(d);
return 0;
}
阅读全文