Single Phase Constructor

Single phase constructor is to push a pointer to the clean-up stack, and then complete its construction. It uses the macro CONSTRUCTORS_MAY_LEAVE that is necessary to ensure whether the cleanup is correctly handled in the event that a constructor may leave beneath a call to new(ELeave).

Characteristics of single phase constructor

The following are the major characteristics of single phase constructor:

  • The implementation of NewL becomes much simpler

  • By using RAII classes in fields to manage owned resources, constructor exception-safety can be maintained

  • Cleanup stack technology

Example

The following code snippet implies the usage of single phase constructor using CONSTRUCTORS_MAY_LEAVE macro.


        class CManagedUserSinglePhase : public CBase
            {
            public:
            CONSTRUCTORS_MAY_LEAVE
            static CManagedUserSinglePhase* NewL(CTicker* aTicker)
                {
                    return new(ELeave) CManagedUserSinglePhase(aTicker);
                }
            }