The realloc function with two-dimensional dynamic array

  c++, dynamic-arrays, memory-reallocation, realloc, templates
template<typename T>
class table{
    T **p;
     int sp;
     int ze;
    public:
     table(const vector<T> vc, int n)
     {
          sp = n;
          //sp = *(&arr + 1) - arr;
          p = new int *[sp];
          ze = 1;
          for (int i = 0; i < sp; i++)
          {
               p[i] = new int[1];
               *p[i] = vc[i]; //
               
          }
    }
};

The problem is that I cannot change the size of the two-dimensional dynamic array where its datatype template is

void table_enlarge(){
      this->sp++;
      this->p = (T **)realloc(p, this->sp * sizeof(T)); //Speicher für Daten und Speicher für Pointer
      for (int i = 0; i < this->ze; i++){
           this->p[i][this->sp - 1] = 0;
      }
 }

Source: Windows Questions C++

LEAVE A COMMENT