D
D
Drottarutarnum2019-03-18 02:31:43
C++ / C#
Drottarutarnum, 2019-03-18 02:31:43

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

4 answer(s)
J
jcmvbkbc, 2019-03-18
@Drottarutarnum

bool& operator [] (int index) {
    return selfVector[index];
  }

should become
std::vector<bool>::reference operator [] (int index) {
    return selfVector[index];
  }

E
Evgeny Petryaev, 2019-03-18
@Gremlin92

Write with templates

Петр, 2016-11-28
@kyklaed

Так значит у вас нет такой таблицы в базе.
Миграцию делали после добавления модели?
python manage.py migrate --run-syncdb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question