 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kevin Frey Guest
|
Posted: Sat Oct 25, 2003 8:25 am Post subject: Namespace Priority During Function Lookup |
|
|
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 |
|
 |
|
|
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
|
|