MOOC清华《面向对象程序设计》第4章:向上映射实验
#include <iostream>
using namespace std;
class Base{
public:
void print(){
cout << "Base::print()" << endl;
}
};
class Derive:public Base{
public:
void print(){
cout << "Derive::print()" << endl;
}
};
void fun(Base obj){
obj.print();
}
int main(){
Derive d;
d.print();
fun(d);
return 0;
}第二行显示Base的原因是fun()函数的形参类型是Base。
软件业务请联系QQ:3121432464“正聪科技客服”
posted on 2017-10-05 18:17 sunshineman1986 阅读(104) 评论(0) 收藏 举报
浙公网安备 33010602011771号