| 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. "),myExample->iInt); //delete delete myExample; } |
在这个例子中没有检查 myExample 所指的这个对象内存分配是否已经成功,而直接使用了它, new() 已经保证了内存分配操作是成功的。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10294527/viewspace-126419/ ,如需转载,请注明出处,否则将追究法律责任。