TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CAMERON CLARK
from: JONATHAN DE BOYNE POLLARD
date: 1998-01-02 01:13:00
subject: Awareness ?

 JJ>>> class foo { private:
 JJ>>>   static int HowMany ;
 JJ>>> public:
 JJ>>>   foo() { ++HowMany ; }
 JJ>>>   ~foo() { --HowMany ; }
 JJ>>> } ;
 JD>> This scheme doesn't work unless you provide a copy constructor as
 JD>> well.
 CC> What about the fact that HowMany is not initialized and can be    
 CC> any number at runtime?
That's not the case.
If foo::HowMany were not *defined* (as it isn't in the above) then the 
program would not link.  I was generously assuming that foo::HowMany is 
defined somewhere, since that is just nitpicking.
However, even if foo::HowMany were defined without an initialiser
        static int foo::HowMany ;
then it would be zero-initialised.  Objects with static storage duration are 
guaranteed to be statically initialised to zero at program startup in C++.  
It is only objects with heap storage duration or with automatic storage 
duration where one has the problem of the "indeterminate value" if one does 
not use an initialiser.
 ¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.