访问控制与封装 — 计算机判断题
题目
阅读下面类定义: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 的成员函数。