已知Parent类及其子类Child1,Child2的定义如下:class Parent {public:virtual ~Parent( ) { }virtual void f( ) = 0 ;};class Child1:public Parent {public:virtual ~Child1( ) { }virtual void f( ){g( );}int g( ) { /*略 */ }};class Child2:public Parent {public:virtual ~Child2( ) { }virtual void f( ){ k( );}private:void k( ) { /*略*/}};下面的代码,哪个无法体现多态性的应用价值:
A. class A {public:virtual ~A( ) { }voiduserParent( Parent * pparent) { if(pparent) pparent->f( ); }};
B. class A {public:virtual ~A( ) { }voiduserParent( Parent & parent) { parent.f( ); }};
C. class A {public:virtual ~A( ) { }voiduserParent( ) { mparent.f( ); }private:Parent mparent;};
D. class A {public:virtual ~A( ) { }voiduserParent( ) { if(mpprent) mpparent->f( ); }private:Parent * mpparent;};