given:
namespace root { namespace parent { namespace childa
class hard_to_get_at{};
}}}
namespace root { namespace parent { namespace childb
// how do I refer refer to namespace childb relative to the current namespace ?
..::hard_to_get_at instance_of_childa_class; // psuedo syntax
}}}
Do I need to specify the full path of the namespace? Is there some way around it ?
Next should work :
namespace root{
namespace parent{
namespace childb{
// some function where you want to use class hard_to_get_at
void foo()
{
childa::hard_to_get_at obj;
// do stuff
}
} // namespace childb
} // namespace parent
} // namespace root
I have not tried it, but as far as I remember
childa::hard_to_get_at sibling;
should work from within childb
without the need for defining a namespace alias. this is a property of C++ namespace resolution, which is able to move up the hierarchy of nesting to search for namespaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With