如何在几个文件之间使用命名空间 [英] How to use namespace across several files
本文介绍了如何在几个文件之间使用命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到C ++的 std
命名空间分布在多个文件中(如向量
, string
, iostream
等)。我如何在我的程序中完成同样的事情?我只需在每个单独的头文件中声明相同的命名空间,就像这样:
I notice that C++'s std
namespace is spread across several files (like in vector
, string
, iostream
, etc.). How can I accomplish the same thing in my programs? Do I simply declare the same namespace in each individual header file, so that it's something like:
ah
namespace something
{
class A {};
}
bh
#include "a.h"
namespace something
{
class B : public A {};
}
然后在 main.cpp
,我将只包括bh和ah,然后使用命名空间的东西;
使用这两个类?
And then in, say, main.cpp
, I would just include "b.h" and "a.h" and then using namespace something;
to use the two classes?
推荐答案
是的,这是正确的做法。
Yes, that is exactly how to do it.
这篇关于如何在几个文件之间使用命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文