好吧,我有以下问题..我有main.cpp
#include "serverClass.h"
...
然后在serverClass.h中,
#ifndef SERVERCLASS_H_
#define SERVERCLASS_H_
#include <stdio.h>
#include <stdlib.h>
#include "clientThread.h"
....
并在clientThread中,
class ClientThread {
private:
serverClass* server;
....
但是当它尝试编译ClientThread时,它说serverClass不是一个类型,因为它还没有编译。我无法避免在serverClass中包含clientThread.h。有没有告诉编译器有一个名为serverClass的类型尚未编译?
答案 0 :(得分:3)
您需要转发声明serverClass
:
class serverClass;
class ClientThread {
private:
serverClass* server;
....
答案 1 :(得分:2)
在clientThread.h中,在ClientThread
类定义之前,您可以forward-declare ServerClass
类:
// Forward declaration
class ServerClass;
class ClientThread {
private:
ServerClass* server;
....