Path: utzoo!attcan!uunet!jarthur!usc!ucsd!swrinde!zaphod.mps.ohio-state.edu!samsung!umich!sharkey!amara!des From: des@amara.uucp (Dave Steinhoff) Newsgroups: comp.lang.c++ Subject: Re: Initialization of static class members? Message-ID: Date: 3 Oct 90 13:48:17 GMT References: <114@hewey.dms.cdc.com> <58170034@hpclscu.HP.COM> Sender: news@adi.COM Organization: /var/news/organization Lines: 31 In-reply-to: shankar@hpclscu.HP.COM's message of 1 Oct 90 23:15:44 GMT In article <58170034@hpclscu.HP.COM> shankar@hpclscu.HP.COM (Shankar Unni) writes: >> The "official way" to initialize a static member is not in the declaration, >> and not in the constructor, but in the actual definition. >> >> A static member *must* have an actual externally-visible definition >> *outside* the class body, in one compilation unit only, as in: >> >> // butthead.h >> >> class butthead { >> static int n; >> }; >> >> // butthead.C >> >> extern int butthead::n = 0; // definition. ^^^^^^ The "extern" specifier is wrong. The definition must appear in exactly one file, but since the static member is effectively a global, it must not be extern. See ARM, pp 180-181. Dave -- ------------------------------------------------------------------- Dave Steinhoff Applied Dynamics, Int'l des@amara.UUCP 3800 Stone School Rd. des@adi.com Ann Arbor, Mi 48108 ...uunet!amara!des (313)973-1300 -------------------------------------------------------------------