<<< Using named rectangles | Index | C++ constructor initializer lists >>> |
The solution to named rectangles is very simple because our Rectangle struct does not allocate/deallocate any memory.
However, let's try a new requirement:
have the Rectangle allocate space to keep its own copy of the name string in memory.
In C++, this can be done with new and delete operators. In C, you use malloc() and free().
Note that in C++, dynamic memory is allocated on the "free store", in C - on the "heap". Why the difference? Because both compilers use a dynamic memory manager that does the work, and how it's done is different in C and C++. You should not mix calls to malloc() / free() with new / delete operators in the same C++ program.
<<< Using named rectangles | Index | C++ constructor initializer lists >>> |