A letter to the editor


This is reproduced from the August 1995 issue of Overload.
Dear Editor,

You invited comments on namespaces, so here are mine. Please bear in mind I'm only starting out with C++. I would have thought that when searching for a variable the search should have gone:

Local => (Namespace if specified) => Global

From my understanding of your examples, which may be limited, it seems if a global variable and a namespace variable exist and you then use the namespace and attempt to access the duplicated name the result is ambiguous. Why is this? Surely if you have specified a namespace it should have precedence over the global settings. I do agree with finding of local variables first if they exist, but I really think that namespaces should be searched before globals. I'm not so sure about the usage of two different namespaces with the same variable names, what happens if you have

	namespace A {
	  int j;
	}

	namespace B {
	  using namespace A;
	  int j;  // Or perhaps even worse long j,
	          // or int *j
	}

What happens in this situation?

Regards,
Barry Dorrans


My response was a lengthy explanation of namespaces published in Overload 10.