Playlist Move Semantics Over an Array of Track Pointers
mediumQuestion 737Track and most of Playlist are written for you. m_tracks is a pointer to an ARRAY OF POINTERS: the array came from new Track*[n] and each element holds the address of a Track created with new, which is why the destructor deletes every slot in a loop and then the array. Moving a playlist moves ONE pointer, the address of that array; the tracks themselves stay where they are, and only the moved-from playlist must forget them. Write the move constructor and the move assignment operator (both noexcept):
- Playlist(Playlist&& other) noexcept: take over other's array and count, then leave other with nullptr and 0
- Playlist& operator=(Playlist&& other) noexcept: do nothing when the source is this object; otherwise delete every track this playlist owns and its array (the same loop as the destructor, written out here), take over other's array and count, leave other empty, and return *this
Write every loop inside the special member that needs it; do not add private helper functions.
The driver reads n lines of seconds title into a playlist, move-constructs a second playlist from it and prints both, move-assigns the second into a playlist that already holds a Filler track and prints both, then move-assigns that playlist to itself through a reference and prints it. An empty playlist prints Empty playlist.
For the input:
2
95 Intro
240 Main Themethe exact output is what is shown in Expected Output.
Free the memory you allocate — this question checks for memory leaks.
Do NOT write a main function.
Expected output
Empty playlist Playlist (2) Intro [95s] Main Theme [240s] Empty playlist Playlist (2) Intro [95s] Main Theme [240s] Playlist (2) Intro [95s] Main Theme [240s]
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...