C++ 不带#的标题说明包括
我正在阅读Doom 3 SDK(在VS解决方案中)中的一些代码时,发现了如下标题:C++ 不带#的标题说明包括,c++,visual-studio,header,C++,Visual Studio,Header,我正在阅读Doom 3 SDK(在VS解决方案中)中的一些代码时,发现了如下标题: #ifndef __PLAYERICON_H__ #define __PLAYERICON_H__ class idPlayerIcon { public: idPlayerIcon(); ~idPlayerIcon(); ...... // omitted public: pla
#ifndef __PLAYERICON_H__
#define __PLAYERICON_H__
class idPlayerIcon {
public:
idPlayerIcon();
~idPlayerIcon();
...... // omitted
public:
playerIconType_t iconType;
renderEntity_t renderEnt;
qhandle_t iconHandle;
};
#endif /* !_PLAYERICON_H_ */
#ifndef _STDAFX_H_
#define _STDAFX_H_
#include "playerIconAndOtherVariables.h"
#include "thatFileYouListed.h"
#endif
标头没有前向类声明,也没有#包含,因此,根据我的经验,它应该会导致一个错误,如:未声明的标识符或语法错误,导致renderEntity_t和qhandle_t不“可见”。
那么,如何才能正确编译?
提前感谢您的回答。因为每次包含它时,所需的实体都会在它之前被向前声明/包含,所以所有内容都是在包含点定义的。正如您正确地说的,它不会以任何其他方式工作。因为每次包含它时,所需的实体都会在它之前被向前声明/包含,所以所有内容都是在包含点定义的。正如您所说,它不会以任何其他方式工作。我想在包含此文件之前,它们会包含其他标题。我想在包含此文件之前,它们会包含其他标题。由于这是一个标题文件,因此可能会有一个顺序将其包含在其他地方(可能使用此文件的地方?)。只要renderEntity和qhandle在包含此文件之前未将其放入符号表中,这并不重要。由于这是一个头文件,可能会有一个顺序将其包含在其他位置(可能使用此文件的位置?)。只要renderEntity和qhandle在包含此文件之前未将其放入符号表中,则无所谓。是否有所谓的stdafx.h?大多数VS项目都有这些 它只是一个包含应用程序所需的所有文件的头文件,以减少包含头文件的编译时间 因此,它将包含如下内容:
#ifndef __PLAYERICON_H__
#define __PLAYERICON_H__
class idPlayerIcon {
public:
idPlayerIcon();
~idPlayerIcon();
...... // omitted
public:
playerIconType_t iconType;
renderEntity_t renderEnt;
qhandle_t iconHandle;
};
#endif /* !_PLAYERICON_H_ */
#ifndef _STDAFX_H_
#define _STDAFX_H_
#include "playerIconAndOtherVariables.h"
#include "thatFileYouListed.h"
#endif
有叫stdafx.h的东西吗?大多数VS项目都有这些 它只是一个包含应用程序所需的所有文件的头文件,以减少包含头文件的编译时间 因此,它将包含如下内容:
#ifndef __PLAYERICON_H__
#define __PLAYERICON_H__
class idPlayerIcon {
public:
idPlayerIcon();
~idPlayerIcon();
...... // omitted
public:
playerIconType_t iconType;
renderEntity_t renderEnt;
qhandle_t iconHandle;
};
#endif /* !_PLAYERICON_H_ */
#ifndef _STDAFX_H_
#define _STDAFX_H_
#include "playerIconAndOtherVariables.h"
#include "thatFileYouListed.h"
#endif
呃,调试这些东西总是很有趣。呃,调试这些东西总是很有趣。不,没有..但是我会检查另一个预编译头,可能用另一个名字:)谢谢输入不,没有..但是我会检查另一个预编译头,可能用另一个名字:)谢谢输入