如何从主类之外的嵌套类中编写实际代码 [英] How to write the actual code from a nested class outside the main class

查看:98
本文介绍了如何从主类之外的嵌套类中编写实际代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过在主类之外编写嵌套类的实际代码来保持代码可读性。是否可能,以及如何?

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
};

我想写如下:

class AA{
  //random code
  //<declaration of class BB>
  // random code
};

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

,BB类只能在AA类中访问...

and the BB class should only be accessible within the AA class...

推荐答案

class A {
    class B;
};

class A::B {
    // ...
};

这篇关于如何从主类之外的嵌套类中编写实际代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆