How to write actual code from a nested class outside the main class

I would like to keep the code readable by writing the actual code of the nested class outside the main class, is it possible and how?

class AA{ //random code class BB : public CC <double> { // very long code }; // random code }; 

I would like to write something like:

 class AA{ //random code //<declaration of class BB> // random code }; class BB : public CC <double>{ // very long code }; 

and BB should only be available in AA ...

+4
source share
2 answers
 class A { class B; }; class A::B { // ... }; 
+11
source

Is this what you want?

 #include <iostream> using namespace std ; class AA{ class BB{ friend class AA ; void VeryLongFunction() ; }; public: void f(){ BB bb ; bb.VeryLongFunction() ; } }; void AA::BB::VeryLongFunction(){ cout << "I am a very long function" << endl ; } int main(){ AA aa ; aa.f() ; } 
+2
source

Source: https://habr.com/ru/post/1379608/


All Articles