Nested Local Classes
It is possible to nest a class inside a local class. In this case, the nested class definition can appear outside the local-class body. However, the nested class must be defined in the same scope as that in which the local class is defined.
void foo(){ class Bar { public: // ... class Nested; // declares class Nested }; // definition of Nested class Bar::Nested { // ... };}
As usual, when we define a member outside a class, we must indicate the scope of the name. Hence, we defined Bar::Nested, which says that Nested is a class defined in the scope of Bar.
A class nested in a local class is itself a local class, with all the attendant restrictions. All members of the nested class must ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access