Skip to Content
Mastering C++ Programming
book

Mastering C++ Programming

by Jeganathan Swaminathan
September 2017
Beginner to intermediate
384 pages
8h 4m
English
Packt Publishing
Content preview from Mastering C++ Programming

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Multi-Paradigm Programming with Modern C++

Multi-Paradigm Programming with Modern C++

Georgy Pashkov

Publisher Resources

ISBN: 9781786461629Supplemental Content