#3896. [GESP202606 六级 C++] 第 3 题

[GESP202606 六级 C++] 第 3 题

下面代码在 main() 中有一行会导致编译错误,请找出来。

class Student {
    public:
    Student(string n, int s) : name(n), score(s) {}
    string getName() {
        return name;
    }
    void setScore(int s) {
        score = s;
    }
    private:
    string name;
    int score;
};
int main() {
    Student stu("Tom", 85);
    cout << stu.getName(); // 1
    stu.setScore(90); // 2
    stu.score = 100; // 3
    cout << stu.getName(); // 4
    return 0;
}

{{ select(1) }}

  • 1
  • 2
  • 3
  • 4