Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Static member definition vs. declaration? Message-ID: <693@taumet.com> Date: 25 Apr 91 18:37:32 GMT References: <1848@dinl.mmc.UUCP> <186@devnull.mpd.tandem.com> <37226@ditka.Chicago.COM> Organization: Taumetric Corporation, San Diego Lines: 32 avraamid@camelback.crd.ge.com (David Avraamides) writes: ># You *do*. A static member only serves as a declaration, and not a ># definition hence a definition still needs to be provided. >What if its not public? Does this make sense? Of course. Private member functions still need to be defined somewhere, and so do private static data members, for example. The fact that they are defined does not make them more available to client functions. >I use a static numInstances variable in my root class and ++ it in >all constructors and -- it in all destructors. I don't want it to >be publicly visible. What if I don't want it to start at 0? (My >compiler doesn't make me initialize it.) Root.h: ======= class Root { ... private: static int numInstances; ... }; Root.c: ======= int Root::numInstances = ; Only members and friends of class Root can get at numInstances, since it is private; no user can see the initializer, since it is hidden in file Root.c. In C++, this is the best you can do with any private data or function. -- Steve Clamage, TauMetric Corp, steve@taumet.com