Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!helios!sparc27!jeffw From: jeffw@sparc27.tamu.EDU (Jeffrey A Waller) Newsgroups: comp.lang.c++ Subject: Re: Initializing static area of classes.... Message-ID: <13174@helios.TAMU.EDU> Date: 8 Mar 91 06:39:39 GMT References: <1991Mar4.224519.6434@bronze.ucs.indiana.edu> <2390@calmasd.Prime.COM> Sender: usenet@helios.TAMU.EDU Reply-To: jeffw@sparc27.tamu.EDU (Jeffrey A Waller) Organization: Computer Science Department, Texas A&M University Lines: 44 In article <2390@calmasd.Prime.COM>, wlp@calmasd.Prime.COM (Walter L. Peterson, Jr.) writes: |> In article <1991Mar4.224519.6434@bronze.ucs.indiana.edu> nsundare@copper.ucs.indiana.edu (Neelakantan Sundaresan) writes: |> > |> >I am trying to solve the problem of initializing the static(shared) data |> >area of a class type. Basically I would like this initializtion and any |> >other house keeping stuff done, when the first object instance of that |> >class is 'construct'ed. Is there a neat way to achieve this? |> > |> |> There is no "neat" way to do this. There is, however, "A" way to do |> this. What you need to do is create yet another class. I would only agree if this data area included static class members which required dynamic initialization. Otherwise leave everything in the class: class Foo { private: static int count; . . . void initialize_static_stuff(); public: Foo() { if(!count++) initialize_static_stuff(); . . . } }; Obviously, there are restrictions, though it works with what I find to be the most common sort of initialization -- calling malloc and/or new. -Jeff