问题
I would like to keep the code readable by writing the actual code of a 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 the BB class should only be accessible within the AA class...
回答1:
class A {
class B;
};
class A::B {
// ...
};
回答2:
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() ;
}
来源:https://stackoverflow.com/questions/8006830/how-to-write-the-actual-code-from-a-nested-class-outside-the-main-class