game.h needs:
- packet.h
- socket.h
server.h needs:
- socket.h
socket.h needs:
- game.h
当我尝试将 socket.h 包含到 game.h 中时,问题就来了,因为 socket.h 已经包含了 game.h。我该如何解决这类问题?
最佳答案
通常的方法,在头文件中使用#ifdef 和#define
在 game.h 中:
#ifndef GAME_H
#define GAME_H
.. rest of your header file here
#endif
这样,内容会被多次读取,但只定义一次。
编辑:删除了每个评论标识符开头和结尾的下划线。
关于C++ 头文件 - 困惑!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/384431/