MESSAGE
DATE | 2011-06-05 |
FROM | Ruben Safir
|
SUBJECT | Subject: [NYLXS - HANGOUT] (fwd) Re: Anonymous namespace
|
-- forwarded message -- Path: reader1.panix.com!panix!newsfeed-00.mathworks.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Anonymous namespace Date: Sat, 04 Jun 2011 15:40:46 +1200 Lines: 35 Message-ID: <94tnpvFivcU1-at-mid.individual.net> References: <94rjavFbjiU7-at-mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net A7JWIYx5NoyngTYC7V+j2gubjal/2MMP6GYkwL/xNV4IxxNG+J Cancel-Lock: sha1:D5ZqbidsPoIrneIFOub8XHwfuDg= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: panix comp.lang.c++:1085999
On 06/ 4/11 02:40 PM, Ruben Safir wrote: > Ian Collins wrote: >> On 06/ 3/11 06:29 PM, ruben safir wrote: >>> On 06/02/2011 10:54 PM, Stefan Ram wrote: >>>>>> What is the point of the anonymous namespace. >>>> Names can be hidden from the linker (from other translation >>>> units), even if they should have external linkage. >>> >>> please expand? >> >> One way to look at the anonymous namespace is to consider it a namespace >> with a cryptic name. That name is only known within the current >> compilation unit. Thus anything declared within the namespace can't >> been seen elsewhere because the namespace name is unknown. >> >> So I could write >> >> namespace { int n; } >> >> and n would only be visible within the current compilation unit whereas >> >> int n; >> >> would be globally visible. > > so the annonymous name space must be in the same file as main?
No, it can be an any compilation unit, that's one of the reasons for its existence.
I could have write "namespace { int n; }" in a dozen source files (or a header they include) and there would be a dozen unique instances of n.
-- Ian Collins -- end of forwarded message --
|
|