www.pudn.com > symbianex.rar > TowPhaseConstruct.cpp


// 
// Copyright (c) 2005 NEUSOFT Institute of inforamtion technology ChenDu. 
// All rights reserved. 
// 
// TowPhaseConstruct.cpp 
// example for TowPhaseConstruct 
// 
// Version 1.0 
// by YangZongde 
// 2005-9-28 
 
#include "CommonFramework.h" 
 
class CTest:public CBase 
  	{ 
public : 
	TInt   iVal; 
	}; 
 
class CSimple :public CBase 
{ 
public: 
	void test( ); 
	static CSimple* NewLC(TInt Value); 
	void ConstructL(TInt Value); 
}; 
void CSimple::test( ) 
	{ 
		_LIT(TestIsOk,"Test is ok\n"); 
		console->Printf(TestIsOk);		 
	} 
CSimple* CSimple::NewLC(TInt Value) 
	{ 
		CSimple* self=new(ELeave) CSimple; 
		CleanupStack::PushL(self); 
		self->ConstructL(Value); 
		return self; 
	} 
void CSimple::ConstructL(TInt Value) 
	{ 
	CTest* test=new(ELeave)CTest; 
	CleanupStack::PushL(test); 
	test->iVal=Value; 
	_LIT(KFormatOK,"OK,The number is %d"); 
	console->Printf(KFormatOK,test->iVal); 
	CleanupStack::PopAndDestroy(); 
	} 
 
 
LOCAL_C void doExampleL() 
    { 
	CSimple* simple1=CSimple::NewLC(10); 
//	CleanupStack::PushL(simple1);				//the newlc has a pushl() 
//	CleanupStack::Pop( );						//pop if true ,else invoke panic  
	delete simple1; 
	}