Why is this an issue?
using
directives add additional scopes to the set of scopes searched during name lookup. All identifiers in these scopes become
visible, increasing the possibility that the identifier found by the compiler does not meet developer expectations.
Using-declarations or fully-qualified names restricts the set of names considered to only the name explicitly specified, and so these are safer
options.
Noncompliant code example
namespace NS1 {
int f();
}
using namespace NS1; // Noncompliant
void g() {
f();
}
Compliant solution
namespace NS1 {
int f();
}
void g() {
NS1::f();
}
// Or
using NS1::f; // Compliant, this is a using declaration
void g() {
f();
}
Resources
- MISRA C++:2008, 7-3-4 - using-directives shall not be used.