O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Easier nested namespace syntax

Until the C++14 standard, the syntax supported for a nested namespace in C++ was as follows:

#include <iostream>using namespace std;namespace org {    namespace tektutor {        namespace application {             namespace internals {                  int x;             }        }    }}int main ( ) {    org::tektutor::application::internals::x = 100;    cout << "\nValue of x is " << org::tektutor::application::internals::x << endl;    return 0;}

The preceding code can be compiled and the output can be viewed with the following commands:

g++-7 main.cpp -std=c++17./a.out

The output of the preceding program is as follows:

Value of x is 100

Every namespace level starts and ends with curly brackets, which makes it difficult to use nested namespaces in large applications. C++17 nested ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required