util

问题描述 投票:0回答:1

我正在寻找在C++中包含头文件的最可移植和最有条理的方法。我正在做一个游戏,现在我的项目结构是这样的。

game
| util
| | foo.cpp
| | foo.h
| ...
game-client
| main.cpp
| graphics
| | gfx.cpp
| | gfx.h
| ...
game-server
| main.cpp
| ...

比如说我想从gfx. cpp中加入foo. h. 据我所知,有三种方法可以做到这一点。

  1. #include "../../game/util/foo.h. 这是我目前所做的,但我越深入文件夹结构就越混乱。

  2. #include "foo.h". 我的编辑器(Xcode)只用这个方法就能很好地编译,但我不确定其他编译器的情况。

  3. #include "game/util/foo.h"我的编辑器(Xcode)只需这样编译就可以了,但我不清楚其他编译器的情况。

哪一个是最好的?(最可移植的,最有条理的,对许多文件夹的扩展最好的,等等)

c++ header-files
1个回答
1
投票

© www.soinside.com 2019 - 2024. All rights reserved.