私はC++にかなり慣れていませんが、#includeステートメントは基本的に#includedファイルの内容をそのステートメントの場所にダンプするだけであると理解しています。つまり、ヘッダーファイルに多数の「#include」および「using」ステートメントがある場合、実装ファイルはヘッダーファイルを#includeするだけで済み、コンパイラは他のステートメントを繰り返さなくてもかまいません。 。
でも人はどうですか?
私の主な懸念は、「#include」、「using」、および「typedef」(今では考えている)ステートメントを繰り返さないと、その情報が使用されているファイルから削除されることです。混乱を招く可能性があります。
小さなプロジェクトに取り組んでいて、実際には何の問題も起こらないのですが、より多くの人が取り組んでいる大きなプロジェクトでは、それが重大な問題になる可能性があると想像できます。
次に例を示します。
更新:「Unit」の関数プロトタイプには、戻り型とパラメーターの中にstring、ostream、StringSetが含まれています-実装ファイルでのみ使用されるヘッダーファイルには何も含めていません。
//Unit.h
#include <string>
#include <ostream>
#include "StringSet.h"
using std::string;
using std::ostream;
class Unit {
public:
//public members with string, ostream and StringSet
//in their return values/parameter lists
private:
//private members
//unrelated side-question: should private members
//even be included in the header file?
} ;
//Unit.cpp
#include "Unit.h"
//The following are all redundant from a compiler perspective:
#include <string>
#include <ostream>
#include "StringSet.h"
using std::string;
using std::ostream;
//implementation goes here