← Back to Pointers
Question 738
Order Move Semantics With a String Member
Order Move Semantics With a String Member
Orderowns a heap array of quantities through the simple pointerm_quantities(one pointer, one array, onedelete[]) and also has a plainstring m_customer; an order whose customer is empty is INVALID andnoexcept): - take the customer withstd::move(other.m_customer), take over the array pointer and the count - then make the source invalid on purpose: clearother.m_customer(do not rely on whatstd::moveleaves behind), set its pointer tonullptrand its count to 0 - the assignment operator must do nothing when the source is this object, release the array it already holds before taking over, and return*thisWrite every loop inside the special member that needs it; do not add private helper functions. The driver reads a customer and a count, then that many quantities. It move-constructs a second order from the first and prints both, move-assigns the second into an order built forOmarwith one quantity and prints both, then move-assigns the result to itself through a reference and prints it. A valid order prints asOrder for CUSTOMER:followed by a space and each quantity. For the input: ``Mina 3 2 4 1`` 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:
Invalid order Order for Mina: 2 4 1 Invalid order Order for Mina: 2 4 1 Order for Mina: 2 4 1
= 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.