diff -r 43e37759235e -r 51a74ef9ed63 Symbian3/SDK/Source/GUID-5829247E-2E8E-502F-9051-A59DA8EE71B0.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/SDK/Source/GUID-5829247E-2E8E-502F-9051-A59DA8EE71B0.dita Wed Mar 31 11:11:55 2010 +0100 @@ -0,0 +1,53 @@ + + + + + +CBase-derived +classes and two-phase constructionThis document describes the need for two-phase construction and +how to use second phase constructors. +

When the construction of an object cannot leave (except for out-of-memory +for the allocation of the object itself), then it is appropriate to use the +conventional C++ constructor, which is automatically invoked by new.

+

When the construction of an object may leave, then the object must be pushed +to the clean-up stack, or a pointer to the object must be stored in an object +that would be cleaned up if a leave occurred, before any part of the +construction function is invoked that may leave. To allow this to happen, +construction steps that can leave, are performed not in the C++ constructor, +but in another initialization functions, referred to as a second phase constructor.

+

Thus, the general sequence for two-phase construction is:

+
    +
  1. allocate memory for +the object (and leave if out of memory) using new

  2. +
  3. optionally define a +C++ constructor to perform any construction that cannot leave

  4. +
  5. push a pointer to the +object, or store a pointer to it in a class with cleanup support

  6. +
  7. use the second phase +constructor to perform any part of the construction that might leave

  8. +
+

Note that:

+ +
\ No newline at end of file