Answer the question
In order to leave comments, you need to log in
Why can't the operator be overloaded?
Can't overload operator if return type is bool
If I create a vector from int, then everything is fine
Error:
the initial value of a non-const parameter reference must be a left-hand value
class Test {
private:
vector<bool> selfVector;
public:
Test(vector<bool> &_vector):selfVector(_vector) {}
bool& operator [] (int index) {
return selfVector[index];
}
};
vector<bool> myVector = {true, true };
auto test = Test(myVector);
test[0] = false;
Answer the question
In order to leave comments, you need to log in
bool& operator [] (int index) {
return selfVector[index];
}
std::vector<bool>::reference operator [] (int index) {
return selfVector[index];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question