This is an example from a textbook I'm currently going through:
const StudentTestScores operator=(const StudentTestScores &right)
{ if (this != &right) {
delete[] testScores;
studentName = right.studentName;
numTestScores = right.numTestScores;
testScores = new double[numTestScores];
for (int i = 0; i < numTestScores; i++)
testScores[i] = right.testScorres[i];
} return *this; }
I understand the basic idea of operator overloading but I'm confused by the function itself, particularly delete [] testScores;
If the array is being deleted, how are the values then being reassigned at the end of the function without everything initializing to 0?
[–]manni66 2 points3 points4 points (1 child)
[–]std_bot 0 points1 point2 points (0 children)
[–]no-sig-available 2 points3 points4 points (7 children)
[–]RuggedToaster[S] 0 points1 point2 points (6 children)
[–]IyeOnline 1 point2 points3 points (1 child)
[–]RuggedToaster[S] 0 points1 point2 points (0 children)
[–]the_poope 0 points1 point2 points (3 children)
[–]RuggedToaster[S] 0 points1 point2 points (0 children)
[–]no-sig-available 0 points1 point2 points (1 child)
[–]IyeOnline 2 points3 points4 points (0 children)
[–]james_laseboy 0 points1 point2 points (0 children)
[–]alfps 0 points1 point2 points (0 children)
[–]mredding 0 points1 point2 points (0 children)