我是编程新手,在我开始使用大量头文件后,头文件的主题让我陷入了困境。除此之外,我正在尝试使用预编译头。我还使用 SFML 库,因此我还必须包含那些标头。
现在我有 stdafx.h、main.cpp,然后是 A.h、A.cpp、B.h、B.cpp、C.h、C.cpp、D.h 和 D.cpp 中包含的类 A、B、C 和 D。
如果我将按照什么顺序将标题包含在所有文件中
- 所有类都包含 SFML 类的实例
- 类 D 包含类 A 和类 C 的实例
- 类 C 包含类 B 的实例
我的代码:(注意:所有标头都有标头防护)
stdafx.h:
#include <SFML/Graphics.hpp>
#include <iostream>
A.h
#include "stdafx.h"
class A
{
//sfml class
};
A.cpp
#include "stdafx.h"
#include "A.h"
B.h
#include "stdafx.h"
class B
{
//sfml class
};
B.cpp
#include "stdafx.h"
#include "B.h"
C.h
#include "B.h"
class C: public B
{
};
C.cpp
#include "stdafx.h"
#include "C.h"
D.h
#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"
main.cpp
#include "stdafx.h"
#include "D.h"