Topic: order of creation of static members of class
Author: "H. Stoelinga" <info@cp.nl>
Date: 1999/08/26 Raw View
Hi there,
Can anyone help me out on the following question:
What is the order of creation of static members of a class, and how can it
be modified?
I need to know this due to the following:
- I have a MFC-class derived from CWinApp, CMyApp
- the exe-wizard makes one global variable 'CMyApp theApp'
- this causes the constructor of CMyApp to be called
- member variable of CMyApp is another class, CAnotherClass
- CAnotherClass has static CString class
- this CString class is assigned a value in the contsructor of CAnotherClass
- here my program crashes, due to the fact that my CString class is not
initialised yet (is has a NULL pointer to which it assigns allocated memory)
Hope you can help me out.
Thanks,
Harvey Stoelinga
[ 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 ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/08/26 Raw View
In article <7q2t5f$k68$1@zonnetje.nl.uu.net>, H. Stoelinga <info@cp.nl>
writes
>
>Hi there,
>
>Can anyone help me out on the following question:
>What is the order of creation of static members of a class, and how can it
>be modified?
If defined in the same translation unit, in the order in which they are
declared. If you have defined them in different TUs any order the
implementation elects, including entirely arbitrary.
Francis Glassborow Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
[ 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 ]