Advertisement
Intermediate C++, Namespaces

What is a namespace alias?

Short answer

A namespace alias creates a shorter name for a long or nested namespace, improving readability without a broad using-directive. It's commonly used for deeply nested namespaces or to switch implementations by aliasing one namespace to a chosen name.

Save C++ mock interview
Advertisement
AModel answer
A namespace alias creates a shorter name for a long or nested namespace, improving readability without a broad using-directive. It's commonly used for deeply nested namespaces or to switch implementations by aliasing one namespace to a chosen name.
namespace fs = std::filesystem;
fs::path p = "/tmp";
Real-world example
Aliasing std::filesystem to fs keeps code concise while remaining explicit.
Likely follow-ups
  • How does an alias differ from a using-directive? | When is it useful?
Related topics