#include指令的限制范围 [英] Limiting Scope of #include Directives
本文介绍了#include指令的限制范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个包含 std :: string
的类的头文件。
Let's say I have a header file with a class that uses std::string
.
#include <string>
class Foo
{
std::string Bar;
public:
// ...
}
此头文件的用户可能不想将 std :: string
包含在他/她的项目中。
The user of this header file might not want std::string
to be included in his/her project. So, how do I limit the inclusion to just the header file?
推荐答案
类的用户必须
这确实是C ++编译模型的一个刺激性副作用(基本上从C继承完整)。如果您想完全避免此类事情,您可能需要查看 PIMPL成语。
This is indeed an irritating side-effect of the C++ compilation model (basically inherited intact from C). If you want to avoid this sort of thing entirely, you probably want to take a look at the PIMPL idiom.
这篇关于#include指令的限制范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文