Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我在一个类中声明一个受保护的数据成员时,这意味着它不能访问外部世界,而是派生类。我的问题是
从派生类派生的类可以访问吗?
是的,受保护的数据成员可以在继承层次结构中一路访问。
通常最好避免使用受保护的数据。另一种方法是编写访问私有数据的受保护方法。这将数据封装在单个类中。它还可以轻松地为数据更改设置断点。
是的。(顺便说一句,你可以简单地尝试一下。)