Dmitry
Dmitry

Reputation: 47

May I place "using namespace std" into my namespace, that in a header?

I am writing a small library. Declaration of my classes, functions and others, that uses standard library are in a header file. I know that putting "using namespace" into header is a bad practic. May I put my code in separate namespace and then put "using namespace" into it? Like this:

// header.h
namespace My
{
    using namespace std;
    // declarations
}

Will it be good?

Upvotes: 3

Views: 119

Answers (2)

Vlad from Moscow
Vlad from Moscow

Reputation: 310960

You may do that but it is not a good idea because this can lead to ambiguious names.

Upvotes: 1

Alok Save
Alok Save

Reputation: 206518

Don't do it!
Simply use fully qualified names or using declaration for specific symbols that you want to use.
With this, You will just end up importing the contents of entire std namespace in your namespace My and essentially the header file header.h. Basically, it is going to give you namespace pollution with lot of unused symbols and also increase the compilation time of every translation unit where you include this header.

Upvotes: 3

Related Questions