正如我已經在我的程序上工作,我已經到了一個點,我有大約30多個頭文件。我該如何處理大量的頭文件?
當我開始,我有一個全功能於一身的標題鏈接到我做了迄今爲止所有的頭文件,以及我所需要的項目庫。
使用此格式,我不得不採取5+分鐘,以便僅通過改變一個變量名或一些其他類似的小重新編譯整個程序作爲一個整體。
我以前的計劃是製作所有標題的「層列表」,其中最基本的標題在底部,下一級標題需要這些標題,等等等等,直到我到達main.cpp文件。 (第2層需要最高的第1層等)。在這個想法之後,我最終偏向於製作文件夾組,並且如果我需要該目錄中的所有內容,則有一個Folder.hpp
文件。現在
編譯時,我立即不知所措語法錯誤說,沒有什麼是適當地包括,當包括命令在我的面前坐着的權利。
以下是一些頭,按語法錯誤之一:
===Character.hpp===
#include "../../Pre.hpp"
#include "../Assets/Folder.hpp"
#include "../Control/Folder.hpp"
#include "../WorldObj.hpp"
===Control/Folder.hpp===
#include "CommonStat.hpp"
#include "DeathHandler.hpp"
#include "EnergySys.hpp"
#include "FactionHandler.hpp"
#include "Interaction.hpp"
#include "Warper.hpp"
#include "WeaponPos.hpp"
===WeaponPos.hpp===
struct WeaponPos{};
===Build Message===
Build Message: error: 'WeaponPos' does not name a type
===NOTE===
The #include lines are the only (seemingly) important portions of the code. the 'struct WeaponPos' is only to show where it is located in terms of the syntax error.
WeaponPos myWpnPos is a variable of Character
忘了inlcude該說明。
什麼是正確有效地組織頭文件以便在編譯源文件時全部負責的好方法?我在Windows 7 64位上使用Code::Blocks和MinGW GCC 4.7。
每個頭文件應包括'#include'它依賴的所有頭文件。 – Galik 2014-10-12 02:26:16
如果是這樣的話,那麼我將不得不爲每個頭文件編寫超過20個#include文件,這些文件都位於複雜的位置。這個想法直到我意識到我總共有50個頭文件爲止 – Molma 2014-10-12 02:28:06