Ray's playground

 

Item 8:Understand the different meanings of new and delete.(More Effective C++)

Though you want to create an object on the heap, use the new operator. It both allocates memory and calls a constructor for the object. If you only want to allocate memory, call operator new; no constructor will be called. If you want to customize the memory allocation that takes place when heap objects are created, write your own version of operator new and use the new operator; it will automatically invoke your custom version of operator new. If you want to construct an object in memory you've already got a pointer to, use placement new.

posted on 2011-06-13 16:33  Ray Z  阅读(148)  评论(0编辑  收藏  举报

导航