我是编程新手,在我开始使用很多头文件后,头文件的话题让我陷入了困境。除此之外,我正在尝试使用预编译的标头。我也在使用 SFML 库,所以我有那些也必须包含在内的标题。
现在我有 stdafx.h、main.cpp,然后是 Ah、A.cpp、Bh、B.cpp、Ch、C.cpp、Dh 和 D.cpp 中包含的 A、B、C 和 D 类。
如果在所有文件中包含标题,我会以什么顺序进行
- 所有类都包含一个 SFML 类的实例
- D 类包含 A 类和 C 类的实例
- C 类包含 B 类的一个实例 我的代码:(注意:所有标题都有标题保护)
stdafx.h:
#include <SFML/Graphics.hpp>
#include <iostream>
啊
#include "stdafx.h"
class A
{
//sfml class
};
A.cpp
#include "stdafx.h"
#include "A.h"
溴化氢
#include "stdafx.h"
class B
{
//sfml class
};
B.cpp
#include "stdafx.h"
#include "B.h"
通道
#include "B.h"
class C: public B
{
};
C.cpp
#include "stdafx.h"
#include "C.h"
DH
#include "A.h"
#include "C.h"
class D
{
A a;
C C; // if left uncommented I recieve a '1 unresolved externals' error
//sfml class
}
d.cpp
#include "stdafx.h"
#include "D.h"
主文件
#include "stdafx.h"
#include "D.h"