Answer the question
In order to leave comments, you need to log in
Overloading [] on Write In C++?
Is it possible to make it so that with the help of an indexer it was possible to assign a value, and not just read it?
MyClass a[5] = {1,2,2}
Answer the question
In order to leave comments, you need to log in
#include <iostream>
template <typename T, size_t N>
class TestArray {
public:
T& operator[](size_t i) {
return data[i];
}
private:
T data[N];
};
int main() {
TestArray<int, 10> arr;
arr[0] = 99;
arr[1] = -1;
std::cout << arr[0] << std::endl;
std::cout << arr[1] << std::endl;
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question