Vect::Vect(const Vect& a) {
size = a.size;
data = new int[size];
for (int i = 0; i < size; i++) {
data[i] = a.data[i];
does the first statement mean i created a copy constructor? then the second means i copied the size of a? not sure with the third, fourth and fifth statements.. please explain to me..
Looks like this copy constructor copies an object of type Vect that looks something like this:
1 2 3 4
class Vect{
int size;
int* data;
}
and when you copy one,
1 2 3 4
size = a.size; // Copy the size member variable
data = newint[size]; // ... then create an array of int, and use the pointer to point at that array
for (int i = 0; i < size; i++) { // ... and then copy the array
data[i] = a.data[i];