tructors and member initializer lists ](/w/cpp/language/constructor
"cpp/language/constructor")  
[ Default member initializer
](/w/cpp/language/data_members#Member_initialization "cpp/language/data
members") (C++11)  
[ ` friend ` specifier ](/w/cpp/language/friend "cpp/language/friend")  
[ ` explicit ` specifier ](/w/cpp/language/explicit "cpp/language/explicit")  
[ Converting constructor ](/w/cpp/language/converting_constructor
"cpp/language/converting constructor")  
Special member functions  
[ Default constructor ](/w/cpp/language/default_constructor
"cpp/language/default constructor")  
[ Copy constructor ](/w/cpp/language/copy_constructor "cpp/language/copy
constructor")  
[ Move constructor ](/w/cpp/language/move_constructor "cpp/language/move
constructor") (C++11)  
[ Copy assignment operator ](/w/cpp/language/copy_assignment
"cpp/language/copy assignment")  
[ Move assignment operator ](/w/cpp/language/move_assignment
"cpp/language/move assignment") (C++11)  
[ Destructor ](/w/cpp/language/destructor "cpp/language/destructor")  
Inheritance  
[ Base and derived classes ](/w/cpp/language/derived_class
"cpp/language/derived class")  
[ Empty base optimization (EBO) ](/w/cpp/language/ebo "cpp/language/ebo")  
[ Virtual member functions ](/w/cpp/language/virtual "cpp/language/virtual")  
[ Pure virtual functions and abstract classes ](/w/cpp/language/abstract_class
"cpp/language/abstract class")  
[ ` override ` specifier ](/w/cpp/language/override "cpp/language/override")
(C++11)  
[ ` final ` specifier ](/w/cpp/language/final "cpp/language/final") (C++11)  
  
[ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/language/classes/navbar_content&action=edit)

A declaration of a [ class/struct ](/w/cpp/language/class
"cpp/language/class") or [ union ](/w/cpp/language/union "cpp/language/union")
may appear within another class. Such declaration declares a _nested class_ .

###  [ [ edit
](/mwiki/index.php?title=cpp/language/nested_types&action=edit&section=1 "Edit
section: Explanation") ]  Explanation

The name of the nested class exists in the scope of the enclosing class, and
name lookup from a member function of a nested class visits the scope of the
enclosing class after examining the scope of the nested class. Like any member
of its enclosing class, the nested class has access to all names (private,
protected, etc) to which the enclosing class has access, but it is otherwise
independent and has no special access to the [ ` this ` pointer
](/w/cpp/language/this "cpp/language/this") of the enclosing class.
Declarations in a nested class can use any members of the enclosing class,
following the [ usual usage rules ](/w/cpp/language/data_members#Usage
"cpp/language/data members") for the non-static members.

    
    
    int x, y; // globals
    class enclose // enclosing class
    {
        // note: private members
        int x;
        static int s;
    public:
        struct inner // nested class
        {
            void f(int i)
            {
                x = i; // Error: can't write to non-static enclose::x without instance
                int a = sizeof x; // Error until C++11,
                                  // OK in C++11: operand of sizeof is unevaluated,
                                  // this use of the non-static enclose::x is allowed.
                s = i;   // OK: can assign to the static enclose::s
                ::x = i; // OK: can assign to global x
                y = i;   // OK: can assign to global y
            }
     
            void g(enclose* p, int i)
            {
                p->x = i; // OK: assign to enclose::x
            }
        };
    };

[ Friend ](/w/cpp/language/friend "cpp/language/friend") functions defined
within a nested class have no special access to the members of the enclosing
class even if lookup from the body of a member function that is defined within
a nested class can find the private members of the enclosing class.

Out-of-class de