header file namespace

Can we put using namespace std; in a header file? Someone told me not to do it, but I don't know why... Thanks!
You can but you absolutely should not to.
for example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//point.h
class point
//...
int distance(point&, point&)
//...

//your header.h
using namespace std;
//...

//main.cpp
#include<algorithm>
#include "your_header.h"
#include "point.h" 
There will be an error. Guess why. Probably even if you will see error you will still won't understand why it is happens, and will waste countless hours trying to find cause of it.

That is because of using namespace std;

Problem with it, that you cannot tpop using namespace, so it will propagate to the end of file.

Do not use using namespace in header and before headers. Use it (better to not use it actually) only after all includes.
Last edited on
Thanks!
Topic archived. No new replies allowed.