[单选题]

( 31 ) 有如下类定义 :

class MyBase{

int k;

public:

MyBase(int n=0):k(n){ }

int value( )const{ return k;}

};

class MyDerived: MyBase{

int j;

public:

MyDerived(int i): j(i) {}

int getK( )const{ return k; }

int getJ( )const{ return j; }

};

编译时发现有一处语法错误 , 对这个错误最准确的描述是

A. )函数 getK 试图访问基类的私有成员变量 k

B. ) 在类 MyDerived 的定义中,基类名 MyBase 前缺少关键字 public ,protected 或 private

C. )类 MyDerived 缺少一个无参的构造函数

D. )类 MyDerived 的构造函数没有对基类数据成员 k 进行初始化

参考答案与解析:

相关试题

有如下类定义:class MyBase{int k;public:MyBase(

[单选题]有如下类定义: class MyBase{ int k; public: MyBase(int n=0):k(n){} int value( )const{return k;} }; class MyDerived:MyBase{ int j; public: MyDerived(int i):j(i){} int getK( )eonst{return k;} int getJ( )const{return j;} }; 编译时发现有一处语法错误,对这个错误最准确的描述是A.函数getK试图访

  • 查看答案
  • 有如下类定义: class MyBase { int k; public: My

    [单选题]有如下类定义: class MyBase { int k; public: MyBase(int n=0):k(n) { } int value( )const{ return k;} }; class MyDerived: MyBase { intj; public: MyDerived(int i): j(i) {} int getK( )const{ return k; } int getJ( )const{ return j; } }; 编译时发现有一处语法错误,对这个错误最准确的描述是

  • 查看答案
  • 有如下类声明: class MyBASE{ int k; public: voi

    [单选题]有如下类声明: class MyBASE{ int k; public: void set(iht n){k=n;} int get()coast{return k;} }; class MyDERIVED:pnoted My BASE { protected: int j; public: void set(int m,int n){MyBASE::set(m);j=n;} int get()const{return MyBASE::get()+j;} }; 则类MyDERIVED中保护的数据

  • 查看答案
  • 有如下类声明:class MyBASE{ int k;public: void

    [单选题]有如下类声明: class MyBASE { int k; public: void set(int n){k=n;} int get()const{return k;} }; class MyDERIVED:protected MyBASE { protected: int j; public: void set(int m, int n) {MyBASE::set(m);j=n;} int get()const{return MyBASE::get()+j;} }; 则类MyDERIVED中

  • 查看答案
  • 有如下类声明:class MyBASE{ int k: public; void

    [单选题]有如下类声明: class MyBASE { int k: public; void set(int n){k=n;} int get() const{return k;} }; class MyDERIVED: protected MyBASE { protected: int j; public: void set(int m, int n){MyBASE::set(m);j=n;} int get() const{return MyBASE::get()+j;} }; 则类MyDERIVE

  • 查看答案
  • 有如下类声明:class MyBASE{int k;public:void se

    [单选题]有如下类声明: class MyBASE { int k; public: void set(int n){k=n;} int get()const{return k;} }; class MyDERIVED:protected MyBASE { protected: int j: public: void set(int m,int n){MyBASE::set(m);j=n;} int get()const{return MyBASE::get()+j;} }; 则类MyDERIVED中保护

  • 查看答案
  • 有如下类声明:class MyBASE{int k;public:void se

    [单选题]有如下类声明: class MyBASE{ int k; public: void set(int n){k=n;} int get( )const{return k;} }; class MyDERIVED:protected MyBASE{ protected: intj; public: void set(int m,int n){MyBASE::set(m);j=n;} int get( )const{return MyBASE::get( )+j;} }; 则类MyDERIVED中保护

  • 查看答案
  • 有如下类声明:class MyBASE{int k;public:void se

    [单选题]有如下类声明: class MyBASE { int k; public: void set(int n) {k=n;} int get()const{return k;} }; class MyDERIVED:protected MyBASE { protected. int j; public: void set(int m,int n){MyBASE::set(m);j=n;} int get()const{return MyBASE::get()+j;} }; 则类MyDERIVED中保

  • 查看答案
  • ( 31 )有如下类定义:class XX{int xx;public:XX (

    [单选题]( 31 )有如下类定义:class XX{int xx;public:XX ( ) : xx ( 0 ) {cout<<' A';}XX ( int n ) : xx ( n ) {tout<<' B';}};C.lass YY:public XX{Int yy;public:YY ( ) : yy ( 0 ) {cout+yy;}YY ( int n ) : XX ( n+1 ) , yy ( n ) {cout<<yy;}YY ( int m,

  • 查看答案
  • 有如下类定义:class AA{int a;public:int getRef(

    [单选题]有如下类定义:class AA{int a;public:int getRef() const{return &a;} // ①int getvalue() const{return a;} // ②void set(int n) const{a=n;} // ③friend void show(AA aa) const {cout< // ④};其中的四个函数定义中正确的是A. . ①B. . ②C. . ③D. . ④

  • 查看答案
  • ( 31 ) 有如下类定义 :class MyBase{int k;public