June 2025
Intermediate to advanced
1093 pages
33h 24m
English
The last way to define a namespace is together with inline. You create an inline namespace as in the following listing.
// https://godbolt.org/z/115M1csEE#include <iostream>namespace mylib { namespace v1 { int version() { return 1; } } inline namespace v2 { // current version int version() { return 2; } }}int main() { std::cout << "Version " << mylib::version() << "\n"; // Output: 2 std::cout << "Version " << mylib::v1::version() << "\n"; // Output: 1 std::cout << "Version " << mylib::v2::version() << "\n"; // Output: 2}
Listing 13.7 The identifiers of an inline namespace also go into its surrounding namespace.
With the inline before namespace, you open a normal namespace. In addition, all identifiers are also ...
Read now
Unlock full access