Can you have protected nested classes in C++?

I have a class that only really ever needed by classes in a certain class hierarchy. I wanted to know if it is possible to nest the class in the highest class's protected section and have all the other classes automatically inherit it?

Answers


"Inherit" is the wrong word to use since it has a very specific definition in C++ which you don't mean, but yes you can do that. This is legal:

 class A {
   protected:
   class Nested { };
 };

 class B : public A {
   private:
   Nested n;
 };

And code that is not in A or something that derives from A cannot access or instantiate A::Nested.


Need Your Help

Errors while solving ODE's python

python scipy integrate differential-equations orbital-mechanics

I have a university project in which we are asked to simulate a satellite approach to Mars using ODE's and SciPy's odeint function.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.