title: Invalid operands to binary expression while implementing vector
body: <p>In an assigment, I was asked to create my own <code>Vector&lt;T&gt;</code>, <code>Mathvector&lt;T&gt;</code> (which inherits from vector) and a <code>Polynomial</code> class type.
  I'm getting the following error and couldn't figure out why.</p>
  
  <pre><code>MathVector.h:37:32: error: invalid operands to binary expression ('mathVector&lt;double&gt;' and 'mathVector&lt;double&gt;')
                  if (this[j]&gt;this[j+1])
  </code></pre>
  
  <p>Ihe sort function is in "mathVector.h" and its goal is to sort the vector in ascending or descending order.</p>
  
  <p><strong>This is the error part of the "MathVector.h":</strong></p>
  
  <pre><code>void sort(int index) {
          int i,j;
          int n=this-&gt;get_size();
          if (index==1) {
              for (i=0; i&lt;n-1; i++)
                  for (j=0; j&lt;n-i-1; j++) {
  
                      if (this[j]&gt;this[j+1]) {
                          T temp;
                          temp=this[j+1];
                          this[j+1]=this[j];
                          this[j]=temp;
                      }
                  }
          }
          else {
              for (i=0; i&lt;n-1; i++)
                  for (j=0; j&lt;n-i-1; j++) {
                      if (this[j]&lt;this[j+1]) {
                          T temp;
                          temp=this[j+1];
                          this[j+1]=this[j];
                          this[j]=temp;
                      }
                  }
          }
          return;
      }
  </code></pre>
  
  <p><strong>This is the "vector.h":</strong></p>
  
  <pre><code>template&lt;class T&gt;
  class Vector {
  private:
      int _size;
      int _capacity;
      T *_data;
  
      static T *allocate(int size) {
          return static_cast&lt;T *&gt;(malloc(sizeof(T) * size));
      }
  
      static void copyRange(T *begin, T *end, T *dest) {
          while (begin != end) {
              new((void *) dest) T(*begin);
              ++begin;
              ++dest;
          }
      }
  
      static void deleteRange(T *begin, T *end) {
          while (begin != end) {
              begin-&gt;~T();
              ++begin;
          }
      }
  
  public:
  
      Vector() {
          _size = 0;
          _capacity = 0;
          _data = 0;
      }
  
      ~Vector() {
          deleteRange(_data, _data + _size);
          free(_data);
      }
  
      Vector(const Vector &amp;obj) {
          this-&gt;_size = obj.get_size();
          this-&gt;_data = obj.get_data();
          this-&gt;_capacity = obj.get_capacity();
      }
  
      void insert(const T &amp;value) {
          if (_size != _capacity) {
              new((void *) (_data + _size)) T(value);
              ++_size;
              return;
          }
          int newCapacity;
          if (_capacity == 0) { newCapacity = 1; }
          else (newCapacity = _capacity * 2);
          T *newData = allocate(newCapacity);
          copyRange(_data, _data + _size, newData);
          new((void *) (newData + _size)) T(value);
          deleteRange(_data, _data + _size);
          free(_data);
          _data = newData;
          _capacity = newCapacity;
          ++_size;
      }
  
      void resize(int index) {
          if (index == _capacity) { return; }
          else if (index &gt; _capacity) { _capacity = index; }
          else {
              _capacity = index;
              if (index &lt; _size) {
                  deleteRange(_data + index, _data + _size);
                  _size = index;
              }
          }
      }
  
      T &amp;operator[](int index) {
          T empty;
          if ((index &lt; 0) || (index &gt;= _size)) {
              cout&lt;&lt;"Wrong Index";
              return empty;
          }
          return _data[index];
      }
  
      const T &amp;
      operator[](int index) const {
          T empty;
          if ((index &lt; 0) || (index &gt;= _size)) {
              cout&lt;&lt;"Wrong Index";
              return empty;
          } else return _data[index];
      }
  
      Vector &amp;operator=(const Vector &amp;other) {
          this-&gt;_size = other.get_size();
          this-&gt;_data = other.get_data();
          this-&gt;_capacity = other.get_capacity();
          return *this;
      }
  
  
      friend ostream &amp;operator&lt;&lt;(ostream &amp;os, const Vector &amp;other) {
          os &lt;&lt; "Size: " &lt;&lt; other._size &lt;&lt; " | Capacity: " &lt;&lt; other._capacity &lt;&lt; " | ";
          int i;
          for (i = 0; i &lt; other._size; i++) {
              os &lt;&lt; other[i] &lt;&lt; ",";
          }
          return os;
      }
  
      T *begin() const {
          return _data;
      }
  
      T *end() const {
          return _data + _size;
      }
  
      int get_size() const {
          return _size;
      }
  
      T* get_data() const {
          return _data;
      }
  
      int get_capacity() const {
          return _capacity;
      }
  };
  </code></pre>