C++ Common Knowledge - Essential Intermediate Programming by By

C++ Common Knowledge - Essential Intermediate Programming by By

Author:By
Language: eng
Format: epub
ISBN: 0-321-32192-8
Publisher: Addison Wesley Professional
Published: 2011-10-03T15:10:14.158899+00:00


It's also possible to encourage, rather than discourage, heap allocation. Just make the destructor private:

class OnHeap { ~OnHeap(); public: void destroy() { delete this; } //... };

Any ordinary attempt to declare an automatic or static OnHeap object will result in an implicit destructor call when the object's name goes out of scope.

OnHeap oh1; // error! implicit call of private dtor void aFunc() { OnHeap oh2; //... // error! implicit dtor call for oh2 }

Item 35. Placement New

It's impossible to call a constructor directly. However, we can trick the compiler into calling a constructor for us through the use of placement new.

void *operator new( size_t, void *p ) throw() { return p; }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.