那人怎么办呢?
我的主要担心是,如果我不重复 '#include'、'using',以及现在想起来的 'typedef' 语句,它会将在使用该文件的地方的信息带走,这可能会导致混乱。
我目前只在小项目上工作,所以这不会引起任何问题。但是,在更多人参与的大型项目中可能会成为一个重要问题。
以下是一个示例:
更新:我的“Unit”函数原型包含了字符串、输出流和 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