Changing namespaces

J

John Harrison

Andre Kostur said:
John Harrison said:
John Harrison wrote:
On Wed, 07 Jul 2004 22:20:42 GMT, Russell Hanneken
<[email protected]> [snip]

I think I'm really going to have to look this up in the standard,
which is always a scary prospect. But here's a guess, your version of
the code injects all the std namespace names into the scope of main,
but ::string ignores any names within the scope of main and just
looks directly at the global scope. I could be utterly wrong.

I think you are right.
Section 3.4.3/4
A name prefixed by the unary scope operator :: (5.1) is looked up in
global scope, in the translation unit where it is used. The name shall
be declared in global namespace scope or shall be a name whose
declaration is visible in global scope because of a using-directive
(3.4.3.2). The use of :: allows a global name to be referred to even
if its identifier has been hidden (3.3.7).

I stand corrected. Personally it seems kinda weird, but thems the
breaks. I wonder why the decision was made that using the "::" scope
operation still goes through the "search path"... I would have figured
that by saying "::" you _meant_ global only...

Isn't the point is that there isn't a search path? Once you use 'using
namespace xxx;' within the global namespace all the names in xxx *are*
global.

john
 
A

Andre Kostur

Andre Kostur said:
John Harrison wrote:
On Wed, 07 Jul 2004 22:20:42 GMT, Russell Hanneken
<[email protected]>
[snip]

I think I'm really going to have to look this up in the standard,
which is always a scary prospect. But here's a guess, your version of
the code injects all the std namespace names into the scope of main,
but ::string ignores any names within the scope of main and just
looks directly at the global scope. I could be utterly wrong.


I think you are right.
Section 3.4.3/4
A name prefixed by the unary scope operator :: (5.1) is looked up in
global scope, in the translation unit where it is used. The name shall
be declared in global namespace scope or shall be a name whose
declaration is visible in global scope because of a using-directive
(3.4.3.2). The use of :: allows a global name to be referred to even
if its identifier has been hidden (3.3.7).

I stand corrected. Personally it seems kinda weird, but thems the
breaks. I wonder why the decision was made that using the "::" scope
operation still goes through the "search path"... I would have figured
that by saying "::" you _meant_ global only...

Isn't the point is that there isn't a search path? Once you use 'using
namespace xxx;' within the global namespace all the names in xxx *are*
global.

I would have figured that the "search path" would be used for unqualified
names. Much like specifying an executable in Windows or Unix. Just type
the name, and it searches $PATH for the executable. But if you specify a
full pathname to the file (like /program), then you mean just the
executable in the root directory and no other.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top