Topic: static constructor (?) (was: init. of "static vector<string> a")
Author: Alex Vinokur <alexander.vinokur@telrad.co.il>
Date: 1999/07/06 Raw View
In article <7lso9i$bib$1@nnrp1.deja.com>,
Alex Vinokur <alexander.vinokur@telrad.co.il> wrote:
> In article <7lse8m$8v3$1@nnrp1.deja.com>,
> Henk Jansen <rdr_nl@my-deja.com> wrote:
> > I have static data (class) member:
> >
> > static vector<string> x;
> >
> > the initialization of which, say with {"a","b"}, is causing me
> troubles.
> > Does anyone want to tell me how that's done?
> >
> > Thanks,
> >
> > Henk.
> >
> [snip]
>
> Hi,
>
> Please see below.
> Alex
>
> //#########################################################
> //------------------- C++ code : BEGIN -------------------
> // main.C
>
> #include <string>
> #include <vector>
> #include <iostream>
>
> class BBB;
> class AAA
> {
> friend class BBB;
> private :
> static vector<string> v1_s;
> static void init_static_vector ()
> {
> v1_s.push_back ("xxx");
> v1_s.push_back ("yyyyy");
> v1_s.push_back ("zzzzzzz");
> }
> public :
> AAA () {}
> static void show_static_vector ()
> {
> copy (v1_s.begin (),
> v1_s.end (),
> ostream_iterator<string> (cout, " ")
> );
> }
>
> };
>
> class BBB
> {
> public :
> BBB () {AAA::init_static_vector ();}
> };
>
> vector<string> AAA::v1_s;
> BBB b1;
>
> int main ()
> {
> AAA::show_static_vector ();
> cout << endl;
>
> return 0;
> }
>
> //------------------- C++ code : END ----------------------
>
[snip]
In this program we are using additional class BBB.
Is there something like "static constructor"?
In this case we dont't need class BBB.
Thanks in advance,
Alex
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]