我有widget一个使用std::string. 它在许多地方使用它,通常与std::vector. 所以你可以看到,类型名变得很长而且很烦人。
我想利用using关键字,即using std::string;
问题是,放置它的最佳位置在哪里?
// widget.h file
#ifndef WIDGET
#define WIDGET
// (1)
namespace example {
// (2)
namespace nested {
// (3)
class widget {
public:
// (4)
...
private:
// (5)
std::string name_;
...
};
}
}
#endif
我的问题是:
- 如果我把它放进去,
(1)那么包括在内的每个人widget.h的范围都会被污染string吗? - 在地方
(2)和(3)中,它与 1 中的故事相同。只是命名空间example和example::nested将在第二个文件中被污染,其中包括widget.h? - 在 place
(4)和(5)中,声明是相当孤立的,但它会在实现(Cpp)文件和继承类中可见吗?
提前致谢!