This question already has an answer here:
- Overloading operator new for a class 1 answer
I've started studying C++ with Thinking in C++, B.Eckel a few months ago and since then, I've not encountered in-detail dynamic memory management in a few other materials. However, in C++ Primer, 5th Ed., there's a pretty small chapter that touches a little on dynamic memory management. After studying the chapter a few times, I'm left with a major confusion:
I know there are global versions of operator new and operator delete, and member versions of the same operators. What I'm failing to understand is the difference between them. Are the member versions of those operators just clever tricks using name-resolution and argument dependent lookup to "overload" the global versions, or does the compiler synthesize those operators too if none are provided by the user programmer? What about placement operator new: is it right to assume that I don't get such functionality unless I explicitly provide the code to do so? Can you give me some short examples? Also, can new and delete be used to allocate raw memory, and defer initialization to a later point? Why would one prefer to use the new and delete operators instead of std::allocator?
Aucun commentaire:
Enregistrer un commentaire