Does there exist a way to backtrack a namespace in C++ without using ::fully::qualified::namespace::name form?
Given:
namespace f {
void p() { }
namespace g {
void p() {
[..]::p();
}
}
}
Is there a correct form of the [..], apart from fully-qualifying it (i.e. ::f::p())?
The goal is to not use p(), because infinite recursion is not the goal here, while also not using FQ in order to save space.
Name lookup works from inner scopes outwards so you don’t need to go from the top down each time. Omitting the leading
::effectively gives you lookup that backtracks until it finds the name that you are looking for sof::peffectively backtracks until it finds anfand then looks for apinside thatf. You don’t need a full::f::p()although in your case, asfis in the global namespace, there isn’t a huge typing difference.Consider this example, where the saving for calling
::f::g::f::p()is more obvious.There is no explicit way of forcing lookup to exlcude the immediate scope level (block or namespace, no
..::p()or^::p()or something.