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 16:01:38 +1200 Lines: 46 Message-ID: <94tp12FivcU3-at-mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net raWyRs+NA15yKRA4A16KHAIn0cRXdPbZFQN0UmQPsaBEbOUHOw Cancel-Lock: sha1:sXoAKnXnBNIwqoaIsU8fnbv3cOI= 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++:1086001
On 06/ 4/11 02:48 PM, Ruben Safir wrote: > Michael Doubez wrote: >> On 3 juin, 03:53, ruben safir wrote: >>> what is the anonymous name space and how is it accessed? >> >> In brief, the effect is the same as C 'static' for functions and >> global variables. >> > I'm confused because i thought what static did was create a variable > which isn't destroyed between function calls and remembers its state. > How that was accomplished, I'm uncertain of.
The static keyword suffers from overload abuse. In the global scope, a static variable has local linkage, at function scope it does as you say above.
>> // not in class of function scope >> static int N; // N is only visible in file >> >> static void foo(){ // foo can only be called in file >> // ... >> } >> >> The interest is that it also work on type definition. >> >> namespace { >> >> // Bar can only be seen in file >> class Bar >> { >> // ... >> }; >> >> } >> >> And it has also the same side effect that, when included in multiple >> translation unit (through a header by example), each translation unit >> will have its own definition of the class. This means that, by >> example, class member variables are not shared. > > I thought class member variables are not shared by defauult?
I assumed he was referring to the member variable declarations.
-- Ian Collins -- end of forwarded message --
|
|