So I do have an array class made by myself:
#include <algorithm>
template <class T>
class myArray
{
private:
int length;
T *elements;
public:
myArray()
{
this->length = 0;
this->elements = nullptr;
}
myArray(int len)
{
this->length = len;
this->elements = new T[len];
}
myArray(int* data, int len)
{
this->length = len;
this->elements = new T[len];
std::copy(data, data+len, this->elements);
}
~myArray()
{
delete[] this->elements;
}
};
I think that for now it works. I wanted to check if the elements I pass in the 3rd constructor are getting properly copied, so I wrote this:
int data[] = {1,2,3,4,5};
myArray<int> a (data, 5);
for (auto x: myArray)
{
std::cout << x << '\n';
}
The question is what I have to write in the class, to make it return this->elements, when I just call myArray
. I know that it is possibly trivial, but I don't know how to find it, actually how to call it, to make Google find the answer for me.