A namespace alias is a way to give a shorter or more convenient name to a namespace. You create a namespace alias using the namespace
keyword followed by the alias name and an =
 sign.
For example:
#include <iostream>
namespace VeryLongNamespace {
void Foo() {
std::cout << "VeryLongNamespace::Foo()\n";
}
}
namespace VLN = VeryLongNamespace;
int main() {
VLN::Foo();
}
VeryLongNamespace::Foo()
Here, VLN
is an alias for VeryLongNamespace
. We can use VLN::Foo()
instead of VeryLongNamespace::Foo()
.
You would use a namespace alias:
For example:
namespace A::B::C {
void Foo() {}
}
namespace ABC = A::B::C;
int main() {
ABC::Foo();
}
Answers to questions are automatically generated and may not have been reviewed.
A quick introduction to namespaces in C++, alongside the standard library and how we can access it