测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A67905. 下面的代码在 main() 中有一行会导致编译错误,请找出来。1 class Pet {

单选题

题目描述

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

1 class Pet {
2 public:
3  Pet(string n, int a) : name(n), age(a) {}
4  string getName() { return name; }
5  void birthday() { age++; }
6 private:
7  string name;
8  int age;
9 };
10
11 int main() {
12  Pet cat("奶茶", 2);
13   cout << cat.getName(); // ①
14  cat.birthday(); // ②
15  cat.name = "大橘"; // ③
16  cout << cat.getName(); // ④
17 }


选项(单选)