Lecture overview -- Keyboard shortcut: 'u'  Previous page: What about interfaces in C++? -- Keyboard shortcut: 'p'  Next page: What about prevention of derivation in C++ -- Keyboard shortcut: 'n'  Lecture notes - all slides together  Annotated slide -- Keyboard shortcut: 't'  Alphabetic index  Help page about these notes  Course home    Abstraction Mechanisms, Part 2 - slide 10 : 24

What about nested classes in C++?

Classes can be nested in C++

Similar to inner static classes in Java

No consequences for the nesting of instances of the involved classes

nested-1.cpp
Class Outer that contains class Inner - does not compile.
nested-2.cpp
Class Outer that contains class Inner - friends of each other.
Related examples below ...
nested-2a.cpp
A variant where class Inner is private in Outer - does not compile.
nested-3.cpp
Inner attempts to access to non-static variable in Outer - does not compile.
nested-3a.cpp
Problems solved - This program compiles.