class Wepon {public:virtual ~Wepon( ) { }virtual int attack( ) const =0;};class Horse {public:virtual ~Horse( ) { }virtual int speed( ) const =0;};class Ultraman {public:void fight(Monster& m,Wepon & w, Horse& h) {int v1 = w.attack( );int v2 = h.speed( );/*其它略*/}};已知:会有多种类型的Wepon,各种Wepon攻击力的计算方法和数值都不一样;会有多种类型的Horse,各种Horse的速度的计算方法和数值都不一样;现希望重新定义Ultraman类,并仍能适应Wepon和Horse的变化,那么下面的定义,哪个是可以的?
A. class Ultraman {public:Ultraman(Horse & horse):mh(horse) { }void fight(Monster& m,Wepon & w) {int v1 = w.attack( );int v2 = mh.speed( );/*其它略*/}private:Horse mh;};
B. class Ultraman {public:Ultraman(Wepon& w):mw(&w) { }void fight(Monster& m,Horse & h) {int v1 = mw->attack( );int v2 = h.speed( );/*其它略*/}private:Wepon * mw;};
C. class Ultraman {public:void fight(Monster& m) {int v1 = mw.attack( );int v2 = mh.speed( );/*其它略*/}private:Horse mh;Wepon mw;};
D. class Ultraman:public Wepon {public:void fight(Monster& m,Horse & h) {int v1 = attack( );int v2 = h.speed( );/*其它略*/}};