Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

c++ - How to use namespace across several files

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:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, that is exactly how to do it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...