第20896题 单选题
找出以下C++代码main函数中导致编译错误的代码行

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

class Pet {
public:
 Pet(string n, int a) : name(n), age(a) {}
 string getName() { return name; }
 void birthday() { age++; }
private:
 string name;
 int age;
};

int main() {
 Pet cat("奶茶", 2);
 cout << cat.getName(); // ①
 cat.birthday(); // ②
 cat.name = "大橘"; // ③
 cout << cat.getName(); // ④
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析