Juliet C. answered 04/10/21
Multiple semesters of teaching C++ intro to programming courses
To access a variable from a namespace in C++, you use the namespace identifier followed by two colons, e.g.
Since space2 is nested in space1 in your example, using space1::var will from within space2 will access the space1 value of var.
Note, to access the space2 or space3 values of var from outside space1, each namespace identifier, from outermost to innermost, must be used, as shown in the example below. In addition, the C++ keyword using changes how variables from namespaces are accessed.
Reference: https://www.cplusplus.com/doc/tutorial/namespaces/