C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Namespace Priority During Function Lookup

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Kevin Frey
Guest





PostPosted: Sat Oct 25, 2003 8:25 am    Post subject: Namespace Priority During Function Lookup Reply with quote



Today I have discovered what appears to be a problem with Borland
C++Builder 6.

I have a set of functions in namespace NAME of the form "string
Get_Name( T val )", where T is an enumeration type. The intention of
these functions is to give me the string name corresponding to an
enumeration (eg. for debug purposes). These functions are declared in
HEADER.H.

In another of my compilation units PARSER.CPP (which includes
HEADER.H) I have more functions also of the form "string Get_Name( T
val )" declared within an anonymous namespace (the enumerations are
also declared in the anonymous namespace, because they are private to
the compilation unit). The main classes (which call the Get_Name( )
methods in the anonymous namespace) are defined in the NAME namespace.

Once I added the Get_Name( ) declarations to HEADER.H, BCB6 would no
longer compiler my PARSER.CPP file. Each call to Get_Name( ) in
PARSER.CPP, which *should* have called the Get_Name( ) function in the
anonymous namespace, could not be "seen" by the compiler.

The way I interpret this is that BCB6 saw there was one or more
Get_Name( ) functions in the NAME namespace (ignoring the parameter
types), then ultimately found there was no matching signature, at
which point it did *not* continue to consider the anonymous namespace
(or any other namespace I guess).

My question is: can someone advise (or direct me to an online
reference for) the rules for how lookups are meant to occur across
namespaces. In "playing around" it would also seem that if NS::F( )
calls G( ), then NS::G( ) will be preferred to ANON::G( ), and in fact
no ambiguity will arise from this, which at the very least seems kind
of dangerous?

Thanks

Kevin

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.