Class has two data members: int* array, and int num, the number of elements in said array.
1 2 3 4 5 6 7 8 9
// Copy constructor
Class::Class(const Class& a)
{
num = a.num; // Number of elements in "array"
array = newint[num];
for (int i = 0; i < num; i++) {
array[i] = a.array[i];
}
}
The reason I used *this above is because I want to create a copy of the current Class object in this new object. Is there a better way to do this?