Subject: 用NewL() 和NewLC()实现两阶段构建
admin
Administrator
Rank: 9Rank: 9Rank: 9



UID 1
Digest Posts 0
Credits 2856
Posts 52
Money 11
Reading Access 200
Registered 8-3-2007
Status Offline
Post at 14-3-2007 22:38  Profile | Blog | P.M. 
用NewL() 和NewLC()实现两阶段构建

如果某个复合对象有一个NewL()方法(或NewLC()方法),那么就应该同时包含构造过程的两个阶段。分配阶段之后,如果ConstructL()发生了异常,应该在调用ConstructL()之前将该对象推入到清除堆栈中。例如:

CMyCompoundClass* CMyCompoundClass::NewLC()
{
CMyCompoundClass* self = new (ELeave) CMyCompoundClass;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CMyCompoundClass* CMyCompoundClass::NewL()
{
CMyCompoundClass* self = new (ELeave) CMyCompoundClass;
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(); // self
return self;
}

Top
 


All times are GMT+8, the time now is 7-9-2010 02:49

CopyRight © Symbianx.cn 2007 Powered By Discuz! 5
Clear Cookies - Contact Us - Symbian OS系统[S60,UIQ]开发中文翻译论坛 - Archiver

本站原文版权归原文作者所有,本站译文版权归本站所有,如需转载请注明原文和译文出处,否则追究法律责任