刚开始学习c++的人都会遇到这样的问题:
定义一个类 class A,这个类里面使用了类B的对象b,然后定义了一个类B,里面也包含了一个类A的对象a,就成了这样:
<div class="dp-highlighter" style="font-family: Consolas, 'Courier New', Courier, mono, serif; width: 688px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px; color: #333333; line-height: 26px; text-align: left;">
- //a.h
- #include "b.h"
- class A
- {
- ....
- private:
- B b;
- };
- //b.h
- #include "a.h"
- class B
- {
- ....
- private:
- A a;
- };
|