Provides code snippets to show you how to use new with automatic leave on failure
The case of new failing is so common that a version of operator new() has been written which takes a single parameter ELeave , indicating that it must leave if it was unable to allocate memory.
Use operator new() so that there is no need to check the result of the new .
void doExampleL() { // attempt to allocate, leave if could not CExample* myExample = new (ELeave) CExample; // new (ELeave) replaces new followed by check // do something myExample->iInt = 5; testConsole.Printf(_LIT("Value of iInt is %d.\n"),myExample->iInt); // delete delete myExample; }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.