I'm trying to implement a Copy Constructor for Vectors in C++ and I'm a little bit confused of why this piece of code actually works. Objects doesn't see private members but its reference, in this example, does.
template <typename Data>
class Vector{
private:
uint size;
Data* Elements = nullptr;
public:
Vector()=default;
Vector(uint);
//Copy Constructor
Vector(const Vector<Data>&);
~Vector();
};
template <typename Data>
Vector<Data>::Vector(const Vector<Data>& ref){
this->size = ref.size;
this->Elements = new Data[this->size];
for(uint i = 0; i < this->size; i++)
this->Elements[i] = ref.Elements[i];
}
So...why does my reference 'ref' has access to private members such as size and Elements? Thanks for your help