C++相談室 part86
■ このスレッドは過去ログ倉庫に格納されています
0014デフォルトの名無しさん
2010/11/06(土) 02:47:2811.5 Protected member access [class.protected]
1 When a friend or a member function of a derived class references a protected nonstatic member function or
protected nonstatic data member of a base class, an access check applies in addition to those described earlier
in clause 11.102) Except when forming a pointer to member (5.3.1), the access must be through a
pointer to, reference to, or object of the derived class itself (or any class derived from that class) (5.2.5). If
the access is to form a pointer to member, the nested-name-specifier shall name the derived class (or any
class derived from that class).
要するに基底クラスBasicから派生したクラスが複数存在したとすると、他のクラスから基底クラスの
protectedメンバをいじれる事になってしまい、隠蔽が破られる
そのため特別ルールを設け、この場合はApplicationのポインタもしくはリファレンスもしくはオブジェクト
を介してしかいじれなく制限されている
この場合はvoid Application::Change(Basic& other)のようにApplicationではなくBasicを引数に
取るためエラーになる
■ このスレッドは過去ログ倉庫に格納されています