qimo601 发表于 2013-2-5 02:12:19

c++ 之类的前置声明

 
转自:http://blog.csdn.net/fjb2080/archive/2010/04/27/5533514.aspx 作者:清林,博客名:飞空静渡
刚开始学习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;  
[*]};  
页: [1]
查看完整版本: c++ 之类的前置声明