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.
特定のクラス階層のクラスだけが本当に必要とするクラスがあります。クラスを最上位クラスの保護セクションにネストして、他のすべてのクラスに自動的に継承させることが可能かどうかを知りたいですか?
「継承」は、C++ で意味のない非常に具体的な定義があるため、使用するのは間違った言葉ですが、そうすることができます。これは合法です:
class A { protected: class Nested { }; }; class B : public A { private: Nested n; };
また、A に含まれていないコード、または A から派生したものは、A::Nested にアクセスしたり、インスタンス化したりすることはできません。