Construction order of members/global objects 
Author Message
 Construction order of members/global objects

I have read this in a book, but can someone confirm that the Ansi C++
draft standard states that objects are constructed in the order they
are declared (and destructed in the reverse order)? This applies to
say either all members of a given object, or all global objects in
a given module. How safe is it to rely on this construction order,
and is it considered poor programming practice to do so?

Thanks,

Dylan



Mon, 20 Sep 1999 03:00:00 GMT  
 Construction order of members/global objects

Quote:

>I have read this in a book, but can someone confirm that the Ansi C++
>draft standard states that objects are constructed in the order they
>are declared (and destructed in the reverse order)?

Yes. This is section 3.6.2 and 3.6.3 of the draft. See
  <http://www.maths.warwick.ac.uk/c++/pub/>
for a downloadable & online version of the 1997public
review document.

Quote:
>How safe is it to rely on this construction order,
>and is it considered poor programming practice to do so?

It's safe if you are sure you have a 100% conforming
compiler. I'd consider it bad practice (unless it was really
well documented), because it seems to me it would make
the code more fragile from a maintenance standpoint.

Do you have a specific problem in mind?

  Katy

--

Software Development Engineer
ORMEC Systems                          http://www.ormec.com



Mon, 20 Sep 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Order of construction of static class members ?

2. How can I control static object construction order?

3. Order of 'global' object creation

4. help with global and/or static class member objects

5. help with global and/or static class member objects

6. Question about: FIX: Visual C++ Class Destructors Are Not Called in Reverse Order of Construction

7. construction/deletion of global variables in a com component

8. Construction of local static objects in a multithreaded environment

9. Object Construction

10. global objects in App or Dlg objects in a dialog only app

11. Global Object In Application Object File

12. Global Z-Order ?

 

 
Powered by phpBB® Forum Software