Order Move Semantics With a String Member
mediumQuestion 738Order owns a heap array of quantities through the simple pointer m_quantities (one pointer, one array, one delete[]) and also has a plain string m_customer; an order whose customer is empty is INVALID and print says so. Write the move constructor and the move assignment operator (both noexcept):
- take the customer with std::move(other.m_customer), take over the array pointer and the count
- then make the source invalid on purpose: clear other.m_customer (do not rely on what std::move leaves behind), set its pointer to nullptr and 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 *this
Write 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 for Omar with one quantity and prints both, then move-assigns the result to itself through a reference and prints it. A valid order prints as Order for CUSTOMER: followed by a space and each quantity.
For the input:
Mina 3
2 4 1the 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, so print one after the last line.
Your output
Run your code to see the output here...