i'm learning c++ and i try to know if its possible to use assignment =
operator after call of operator []
I have an array class with private int *_content
data, and the operator =
overloaded.
His constructor alloc my _content
by the size passing in parameter.
My class looks like :
class Array {
private:
int *_content;
public:
Array(unsigned int n) {
this->_content = new int[n];
}
~Array() {
delete[] _content;
}
int operator[](int n) const {
return this->_content[n];
}
};
i can write the following code :
int main() {
Array a(10);
std::cout << a[5] << std::endl;
return 0;
}
result :
0
I would like to know if it's possible to assign at the case n
of my content by any operator after using []
like this :
a[5] = 2000;
And know if there is any clean solution in my case for this situation. Thank you for reply