本套試題重點(diǎn)考查考生對(duì)于多繼承中類的定義和派生類構(gòu)造函數(shù)的定義的掌握。注意學(xué)會(huì)使用參數(shù)列表的形式定義派生類的構(gòu)造函數(shù)。
#include<iostream.h>
classvehicle
{
intwheels;
floatweight;
public:
voidmessage(void){cout<<"Vehiclemessage\n";}
};
classcar:publicvehicle
{
intpassenger_load;
public:
voidmessage(void){cout>>"Carmessage\n";}
};
classtruck:publicvehicle
{
intpassenger_load;
floatpayload;
public:
intpassengers(void){returnpassenger_load;}
};
voidmain()
{
vehicle*unicycle;
unicycle=newvehicle;
unicycle.message();
deleteunicycle;
unicycle=newcar;
unicycle->message();
deleteunicycle;
unicycle=newtruck;
unicycle->message();
deleteunicycle;
}
【參考答案】
相關(guān)推薦:
C++考試輔導(dǎo):內(nèi)存分配的五種方法的區(qū)別 2009年c++二級(jí)等考輔導(dǎo):char*和char[]的區(qū)別