We have in code one common namespace MainNamespace and a lot of namespace per module eg. ModuleNamespace, DifferentModuleNamespace. Module namespaces are inside the main namespace.
When we create a new class and need another class from different module we have to declare some using to avoid writing full namespace path.
What is consider as a good practice in such situation:
Using namespace with full path:
namespace MainNamespace {
namespace ModuleNamespace {
using MainNamespace::DifferentModuleNamespace::Foo;
class MyClass {
void method(Foo);
};
}
}
or remove MainNamespace namespace from path:
namespace MainNamespace {
namespace ModuleNamespace {
using DifferentModuleNamespace::Foo;
class MyClass {
void method(Foo);
};
}
}
or maybe different approach is better?
Edit:
Ok, maybe different question. Is there any situation when using absolute paths to namespace (using A = Main::ModuleA::A;) will be safer than using short paths(using A = ModuleA::C;). When we do it in the same main namespace.
file A.h:
namespace Main
{
namespace ModuleA {
class A
{
public:
A();
~A();
};
class C
{
public:
C();
~C();
};
}
}
file B.h:
#include "A.h"
namespace Main {
namespace ModuleB {
class B
{
using A = Main::ModuleA::A;
using A = ModuleA::C;
public:
B();
~B();
void foo(A a);
void bar(C c);
};
}
}