Roster Deep Copy of an Array of Player Pointers
mediumQuestion 733Player and most of Roster are written for you. m_players is a pointer to an ARRAY OF POINTERS: the array itself was made with new Player*[n], and every element holds the address of a separate Player made with new. A deep copy therefore needs a new array AND a new Player for every slot, and a release needs one delete per slot and then a single delete[] for the array (see the destructor). Write the copy constructor and the copy assignment operator:
- Roster(const Roster& other): copy the team name and the count, allocate a new pointer array, and in a loop store a new Player copied from each of the other roster's players
- Roster& operator=(const Roster& other): do nothing on self-assignment; otherwise delete every player this roster owns and its array, then do exactly what the copy constructor does, and return *this
Write every loop inside the special member that needs it; do not add private helper functions.
The driver reads a team name, n and n lines of number name (the name may contain spaces), then one extra number name. It copy-constructs a second roster, renumbers the copy's first player to 99 and adds the extra player to the copy, prints both; assigns the original into a roster named Reserves that already holds the extra player, renumbers that one's first player to 7 and prints the original and it; then assigns the original to itself through a reference and prints it.
For the input:
Hawks
2
10 Ada Lovelace
23 Grace Hopper
50 Subthe 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
Hawks (2 players) #10 Ada Lovelace #23 Grace Hopper Hawks (3 players) #99 Ada Lovelace #23 Grace Hopper #50 Sub Hawks (2 players) #10 Ada Lovelace #23 Grace Hopper Hawks (2 players) #7 Ada Lovelace #23 Grace Hopper Hawks (2 players) #10 Ada Lovelace #23 Grace Hopper
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...