我有3個類(它可能是300),每個類都有自己的頭和實現。 我想寫一個'優雅'的方式來組織我加載任何三類中的每一類所需的課程。也許這個例子可以幫助...關於標題,轉發和如何組織很多包括
我:class1的類class2 CLASS3
每頭有:
每實現了:
#define DIRECT_STYLE
#include "general.h"
OK 我要去寫一個'general.h'文件,其中我有:
#ifndef DIRECT_STYLE
#ifndef CLASS1_H
#include "class1.h"
#endif
#ifndef CLASS2_H
#include "class2.h"
#endif
#ifndef CLASS3_H
#include "class3.h"
#endif
#endif
#ifndef FORWARD_STYLE
class Class1;
class Class2;
class Class3;
#endif
// a lot of other elements needed
#include <string.h>
#include <stdio.h"
....
#include <vector.h"
(all the class I need now and in the future)
這是一個很好的結構?或者我正在做一些白癡的事情? 我的目標是有一個獨特的'general.h'文件來編寫所有我需要的元素... 這是否正常工作? 謝謝
這有什麼用? –
是的,這很愚蠢。不要在每個TU中都包含所有內容,否則構建時間將會到地獄。 –
我認爲這個策略會讓你在開始得到一個相當複雜的項目時分得一塌糊塗:p –