GESP 六级 · GESP 202512 C++ 六级 第 3 题

选择题 · 答案 C · 考点:函数

← 整套速查表 GESP 六级 全部真题

题目

关于以下代码,说法正确的是( )。

class Instrument {
public:
    void play() {
        cout << "乐器在演奏声音" << endl;
    }

    virtual ~Instrument() {}
};

class Piano : public Instrument {
public:
    void play() override {
        cout << "钢琴: 叮咚叮咚" << endl;
    }
};

class Guitar : public Instrument {
public:
    void play() override {
        cout << "吉他: 咚咚当当" << endl;
    }
};

int main() {
    Instrument* instruments[2];
    instruments[0] = new Piano();
    instruments[1] = new Guitar();

    for (int i = 0; i < 2; ++i) {
        instruments[i]->play();
    }

    for (int i = 0; i < 3; ++i) {
        delete instruments[i];
    }
    return 0;
}
答案:C

考点

函数

解题思维

分析时间复杂度时关注循环层数和每层迭代次数,递归算法则分析递归树。注意最坏/最好/平均情况的区别。

常见错误

分析复杂度时注意外层循环和内层循环的关联。例如内外两层都到n的循环不一定是O(n²),要看内层是否每次都在缩小。

详细解析(节选)

【考点】虚函数机制|override 重写|编译期错误

1. 🎯 考纲定位

本题考查的是 C++ 虚函数机制与 override 关键字的绑定关系,位于 GESP 六级《面向对象编程》模块。命题人专门卡住了"override 不是装饰,是 C++ 标准强绑定"这个认知断层——大量考生看到 override 就默认能重定义,却忘了它必须对应一个已有的 virtual 函数。

同考点真题

在 OI伴学 里做这道题
登录后可计时作答、查看完整六段式解析,并按你的错题自动生成同类练习。
去刷题先做一次 AI 学情诊断