有如下类定义: class Test { public: Test(){a=0;c=0;}//① int f(int a)const{this一>a=a;}//② static int g(){return

admin2019-05-22  17

问题 有如下类定义:
    class Test
    {
    public:
    Test(){a=0;c=0;}//①
    int f(int a)const{this一>a=a;}//②
    static int g(){return a;}//③
    void h(int b){Test::b=b;};//④
  private:
    int a;
    static int b;
    const int C;
    };
    int Test::b=0;
    在标注号码的行中,能被正确编译的是(    )。

选项 A、①
B、②
C、③
D、④

答案D

解析 只能通过构造函数的参数初始化列表对常数据成员进行初始化,本题中常数据成员为c。①通过默认构造函数初始化c,所以不正确。常成员函数只能引用本类中数据成员,而不能修改它,所以②不正确。静态成员函数由于没有this指针,所以不能访问本类中的非静态成员,所以③错误。
转载请注明原文地址:https://jikaoti.com/ti/irA0FFFM
0

相关试题推荐
最新回复(0)