Nested Class Definition in source file

You can. If your inner class has a method like:

  class MyClass   {
    class NestedClass
    {
    public:
      void someMethod();
    };

    // main class members here
  };

…then you can define it in the .cpp file like so:

void MyClass::NestedClass::someMethod() {
   // blah
}

Structures are almost the same thing as classes in C++ — just defaulting to ‘public’ for their access. They are treated in all other respects just like classes.

You can (as noted in comments) just declare an inner class, e.g.:

class MyClass   {
    class NestedClass;
    // blah
};

..and then define it in the implementation file:

class MyClass::NestedClass {
  // etc.
};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)