我有一个关于包括标题的快速问题 我在情况下,我想建立2个类,他们都持有指向其他类的指针。 他们每个人都在不同的标题。 我怎么能包括的方式,我不会得到识别错误的标题我如何包括其他头已经包含我目前的标题
Client.h
#ifndef CLIENT_H
#define CLIENT_H
#include "Viewable.h"
class Client{
Viewable *viewptr;
}
#endif
Viewable.h
#ifndef VIEWABLE_H
#define VIEWABLE_H
#include "Client.h"
class Client{
Client* client;
}
#endif
这段代码给我标识符错误因为有双重定义。 我明白为什么,我该如何避免该错误?
我猜你的意思是写'类Viewable'在你的第二个代码块...的 – wkl
可能的复制[什么是向前声明C++?](http://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c) – wkl
[Resolve头包括循环依赖项]的可能重复(http://stackoverflow.com/questions/ 625799/resolve-header-include-circular-dependencies) – nwp