C++ Primer(第5版) 练习 15.14
练习 15.14 给定上一题中的类以及下面这些对象,说明在运行时调用哪个函数:
base bobj;
base *bp1 = &bobj;
base &br1 = bobj;
derived dobj;
base *bp2 = &dobj;
base &br2 = dobj;
( a ) bobj.print();
( b ) dobj.print();
( c ) bp1->name();
( d ) bp2->name();
( e ) br1.print();
( f ) br2.print();
环境:Linux Ubuntu(云服务器)
工具:vim
代码块
base bobj;
base *bp1 = &bobj;
base &br1 = bobj;
derived dobj;
base *bp2 = &dobj;
base &br2 = dobj;
( a ) bobj.print(); //调用base类print
( b ) dobj.print(); //调用derived类print
( c ) bp1->name(); //调用base类name
( d ) bp2->name(); //调用base类name
( e ) br1.print(); //调用base类print
( f ) br2.print(); //调用derived类print