← Back to Pointers
Question 737
Playlist Move Semantics Over an Array of Track Pointers
Playlist Move Semantics Over an Array of Track Pointers
Trackand most ofPlaylistare written for you.m_tracksis a pointer to an ARRAY OF POINTERS: the array came fromnew Track*[n]and each element holds the address of aTrackcreated withnew, 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 (bothnoexcept): -Playlist(Playlist&& other) noexcept: take overother's array and count, then leaveotherwithnullptrand 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 overother's array and count, leaveotherempty, and return*thisWrite every loop inside the special member that needs it; do not add private helper functions. The driver readsnlines ofseconds titleinto a playlist, move-constructs a second playlist from it and prints both, move-assigns the second into a playlist that already holds aFillertrack and prints both, then move-assigns that playlist to itself through a reference and prints it. An empty playlist printsEmpty playlist. For the input: ``2 95 Intro 240 Main Theme`` the 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 — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.