博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
头文件相互包含出错问题解决
阅读量:6881 次
发布时间:2019-06-27

本文共 841 字,大约阅读时间需要 2 分钟。

        今天写程序遇到了一个问题,花了好几个小时各种找资料都没有解决,终于皇天不负有心人还是让我给把它kill 掉了。什么问题呢?那就是头文件相互包含出错(当然之前我并不知道是这个原因),先来看代码:

Test1.h

1
2
3
4
5
6
7
8
#include "cocos2d.h"
#include "Test2.h"
 
class 
Test1 : 
public 
Layer
{
    
…………
    
Test2 *test2;
};

Test2.h

1
2
3
4
5
6
7
8
#include "cocos2d.h"
#include "Test1.h"
 
class 
Test2 : 
public 
Layer
{
    
…………
    
Test1 *test1;
};

        如果你的代码有与上代码类似的写法,那么在编译时就会因头文件相互包含出错,Windows平台下会提示:

Mac平台下会提示:

解决办法:

Test1.h

1
2
3
4
5
6
7
8
9
#include "cocos2d.h"
 
class 
Test2;        
//只是告诉编译器,需要这个类,其他功能结构等都没
 
class 
Test1 : 
public 
Layer
{
    
…………
    
Test2 *test2;
};

Test1.cpp

1
2
3
#include "Test1.h"
#include "Test2.h"        //真正的包含
………………

Test2.h

1
2
3
4
5
6
7
8
9
#include "cocos2d.h"
 
class 
Test1;        
//只是告诉编译器,需要这个类,其他功能结构等都没
 
class 
Test2 : 
public 
Layer
{
    
……………
    
Test1 *test1;
};

Test2.cpp

1
2
3
#include "Test2.h"
#include "Test1.h"        //真正的包含
………………

这样修改后,问题就解决啦啦啦。。。哎,希望大家不要出现这样的错误。

转载地址:http://fubbl.baihongyu.com/

你可能感兴趣的文章
Tensorflow学习笔记(1):tf.slice()函数使用
查看>>
ORA-01102的解决办法
查看>>
奇怪的iphone6 plus,H5调用拍照浏览器崩溃
查看>>
MVC接受JSON的一些注意事项
查看>>
response对象设置输出缓冲大小
查看>>
MVC+Ninject+三层架构+代码生成 -- 总结(七、顯示層 一)
查看>>
[CF1105D]Kilani and the Game
查看>>
[bzoj4195][Noi2015]程序自动分析
查看>>
简单的bfs(最短路径)c++
查看>>
Matlab2013a许可证过期问题,反复提示激活
查看>>
向上下左右不间断无缝滚动图片的效果(兼容火狐和IE)
查看>>
MongoDB 基础
查看>>
redis分布式集群3种架构方案
查看>>
C++ 编程思想——继承和组合
查看>>
Charles抓包显示乱码解决方法
查看>>
Web前端开发中的MCRV模式(转)
查看>>
VC中的字符串转换宏
查看>>
SVN过滤设置 ...
查看>>
POJ 3185 DFS
查看>>
Nginx服务配置编写
查看>>