我有这样的情况
在文件 GameServer.h 中:
class ServerGameStruct; //I can't simply include ServerGameStruct.h
// because of cyclic dependency
class GameServer {
public:
class Client { };
private:
ServerGameStruct gameStructure_;
}
并在文件 ServerGameStruct.h
#include "GameServer.h"
class ServerGameStruct {
public:
typedef GameServer::Client Client;
// some method which use type Client *
// no class members with type Client
}
编译后我得到错误 GameServer::gameStructure_ 使用未定义的类 GameServerStruct。
如何解决这种头部循环依赖?