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 17:19:37 +1200 Lines: 37 Message-ID: <94ttj9FivcU4-at-mid.individual.net> References: <94rjavFbjiU7-at-mid.individual.net> <94tnpvFivcU1-at-mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net p0XbbejGaIStJjxoig7nFweaYQxiyR9l++Javi60bH5wuGCZmq Cancel-Lock: sha1:MRc8BnJiXv4AQE5Ni6ewvQ1PYGU= 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++:1086009
On 06/ 4/11 04:56 PM, Ruben Safir wrote: > On Sat, 04 Jun 2011 15:40:46 +1200, Ian Collins wrote: > > >>> 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. > > Sorry for being thick about this, but such stuff is not covered in normal > C++ text books. It seems you have to learn it by word of mouth or maybe > I need yet more books. > > A single computational unit is the files that are used to create any > single object file? That would be basically anything that would be > #include (ed) in a source file?
"compilation unit", yes, pretty much.
> Now what makes that interesting is that when I was studying templates, > the declarations and definitions needed to be inside the same file. How > is that related (or the reason why it is not related)to the concept of a > transitional unit? And how does this affect the linking of shared > libraries?
Many, but not all compilers require the declaration and definition of a template to be in the same compilation unit. It doesn't really affect the linking of libraries, There are a couple of techniques used with libraries containing templates. One is to keep all of the template code inline in a header, the other is to instantiate all possibilities in the library.
-- Ian Collins -- end of forwarded message --
|
|