Hello! I wrote my container class. And now I need to write an iterator class so that my container can interact with the algorithms of the standard library. Wrote a class:
class Iterator { public: Iterator(T *first) { current = first; } T &operator+(int n) { return *(current + n); } T &operator-(int n) { return *(current - n); } T &operator++(int) { return *current++; } T &operator--(int) { return *current--; } T &operator++() { return *++current; } T &operator--() { return *--current; } bool operator==(const Iterator &it) { return current == it.current; } bool operator!=(const Iterator &it) { return current != it.current; } T &operator*() { return *current; } private: T *current; }; The code in main:
Array<int> arr; Array<int> arr2; for (int i(160); i >= 0; i -= 5) { arr.append(i); } for (int i(0); i < 180; i += 5) { arr2.append(i); } sort(arr.begin(), arr.end()); As a result, I get a few errors during assembly:
error C2679: binary "-": operator not found, accepting the right operand of the type "Array :: Iterator" (or there is no acceptable transformation)
error C2780: void std :: _ Sort (_RanIt, _RanIt, _Diff, _Pr): requires arguments: 4, available: 3
c = a - b;- here minus binary,c = -a;- and here is a unary ... - Harry