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:
我注意到C ++的std命名空间分布在几个文件中(比如vector,string,iostream等)。我如何在我的程序中完成同样的事情?我是否只是在每个单独的头文件中声明相同的命名空间,因此它类似于:
a.h
namespace something
{
class A {};
}
b.h
#include "a.h"
namespace something
{
class B : public A {};
}
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?
然后在main.cpp中,我只需要包含“b.h”和“a.h”,然后使用命名空间;使用这两个类?
1 个解决方案
#1
21
Yes, that is exactly how to do it.
是的,这正是如何做到的。
#1
21
Yes, that is exactly how to do it.
是的,这正是如何做到的。