towphaseconstruct.cpp

来自「SYMBIAN中经典丛书何伟的实例代码」· C++ 代码 · 共 58 行

CPP
58
字号
//
// 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;
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?