Using static function NewL(), as well as second phase constructor ConstructL(), a long time were signs of code developed for Symbian C++. Many years ago, when C++ exceptions have not yet been standardized, this approach was very usefull, it helped to avoid many problems (associated with memory leaks).
Tho-phase construction remains one of the cornerstones of Symbian C++. Of cource, since in Symbian C++ appeared full support of C++ exceptions, this consept has lost its relevance. However, developers need a clear understanding of this idiom as the approach to create objects of classes. Two-phase construction continues to be used in a variety of system APIs, and likely will be maintained in the future for compatibility reasons.
This article describes the reasons for using such approach of constructing, describes the concept, demonstrates the code example. This material will be particularly useful for beginners.
FireSwarog, 06.09.2009
Two-phase construction is a crucial feature of Symbian C++. The two places where the code should never leave are (1)in the constructor (2) in the destructor. In a constructor initialization code resides. Initialization code may leave if the object if not fully initialized because of some reasons(one of the reason is that the resource file can't get accessed).
To overcome this problem, in symbian two-phase construction comes into picture. The construction of an object is done in two phases. Where the object is first created with default constructor (the code in it never leaves) and then pushing it on to the clean-up stack and then calling the constructor method which can leave. Then popping the object from clean-up stack. This article clearly describes the concept and creation of two-phase construction.
The article can become useful to beginners.--Deepikagohil 16:18, 6 September 2009 (UTC)