CJCoding With Joseph
15free / daySign inCreate account

AudioClip Move Constructor Steals the Samples

AudioClip is written for you except its move constructor. m_samples is a simple pointer to ONE heap array of ints. Write AudioClip(AudioClip&& other) noexcept so the new clip takes over the other clip's array and count, and the other clip is left with nullptr and a count of 0 (so its destructor frees nothing and it reports zero samples). Moving copies one pointer; no sample is copied.

The hidden driver reads n then n sample values into a clip, move-constructs a second clip from it with std::move, and prints the second clip's size, first and last sample on one line, then the source clip's size on the next.

For the input:
``
3
7 8 9
``

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:

moved: 3 samples, first 7, last 9
source: 0 samples

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
3\n7 8 9\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.