Memory Management with Operators and Function Calls

In this section, I compare the use of operators new and delete with the use of functions malloc() and free(). Similar to the previous section, you can skip this section if you feel it is too technical. Make sure you come back to this section for two things: a) the recommendation to use new and delete over malloc() and free(), and b) the criticism of my example for not abiding by the principles of object-oriented programming.

Notice that the constructor is called only after the class object is created by the scope rules or by the operator new. It is not called after a malloc() call. Similarly, the destructor is called only before the object is destroyed by the scope rules or by the operator ...

Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.