计算机 判断题 较难 ★ 精品

访问控制与封装 — 计算机判断题

C++ 程序设计(大学通用) 类与对象 AI 三重审校通过

题目
阅读下面类定义:class Account { private: double balance; public: Account(double b) : balance(b) {} bool transferTo(Account& other, double amount) { if (amount <= 0 || amount > balance) return false; balance -= amount; other.balance += amount; return true; } }; 判断:在成员函数 transferTo 中,语句 other.balance += amount; 不能通过编译,因为 balance 是 other 对象的私有成员,而 transferTo 不是 other 的成员函数。