I know that I the scope of the using directive is limited to a block or a function when put inside. Then it will apply only to that scope. But if the block is a namespace
it apparantly applies through all blocks of the same namespace. Is that correct? At least, the following example suggests that: (http://ideone.com/K8dk7E)
namespace N1
{
struct Foo{};
}
namespace N2
{
using namespace N1;
Foo f;
}
namespace N2
{
Foo f2;
}
int main()
{
N2::f2;
}
I had expected Foo f2
to give an error, since Foo
should be unknown.
So my real question is, is a using
statement within a namespace block in effect for all blocks of the same namespace?
This is causing issues when all cpp files are included and compiled together, as it is polluting the other cpp files, that should not have the other namespace included (the one for which the using directive is put). So, in effect it may cause undesirable conflicts.
using namespace
declarations in header files and instead use forward declarations. – Tortosa