Possible Duplicate:
Is it a good idea to wrap an #include in a namespace block?
// Method One
#ifndef XXX_H
#define XXX_H
#include <iostream>
#include "myhead.h"
namespace XXX
{
/...
}
#endif
OR
// Method Two
namespace XXX
{
#ifndef XXX_H
#define XXX_H
#include <iostream>
#include "myhead.h"
/...
#endif
}
When we define a new namespace XXX, should we move #include directive inside namespace or not?
Thank you
You must not include
<iostream>inside your namespace. You will get linker errors.I would not suggest including any headers within a namespace.
The only exception would be where you have a header which defines only
extern "C"functions (and no C++ functions or classes), you can usually include that in a namespace without causing linker problems. But it is still probably not a good idea.