Hello I was researching the copy constructor and found this exampleo a website:
#include <iostream>
class Array
{
public:
int size;
int* data;
Array(int size)
: size(size), data(new int[size]) {}
~Array()
{
delete[] data;
}
};
int main()
{
Array first(20);
first.data[0] = 25;
{
Array copy = first;
std::cout << first.data[0] << " " << copy.data[0] << std::endl;
} // (1)
first.data[0] = 10; // (2)
}
Is this code vulnerable because when it makes copy=first it is actually linking there adresses or is my understanding of a copy constructor's inner dynamics wrong?