CJCoding With Joseph
15free / daySign inCreate account

Playlist Move Semantics Over an Array of Track Pointers

Track 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 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
Topics:
Pointers
📥 Auto-Input:
2\n95 Intro\n240 Main Theme\n
This input is automatically fed to your program's stdin
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.