problems with pointers and internal representation.

I am trying to implement the representation in the attached file.

class matriz {
      private:
              int fil,col;
              int **filaspointer; 
              int *buffer;       
              
      public:
             matriz();
             matriz(int fil,int col);
             };

matriz::matriz(int fil,int col) {
 fil=fil;
 col=col;
 *filaspointer=new int[fil];
 for (int i=0; i<fil; i++){
     buffer=new int[col];
     filaspointer=buffer;
 }
}


int main () {
    matriz test(2,3);

The program just closes when I execute it (i am 100 % sure its because the pointers are pointing the wrong direction :wall:)
But uh...I cannot see the problem here (maybe it lies down within the representation?).

Well, you are assigning to a dereferenced pointer, but nobody put a pointer in there to dereference, so SEGV; lose the asterisk:

filaspointer=new int[fil];

That won't even compile, it gives me this error in that exact line:

In constructor `matriz::matriz(int, int)':
cannot convert `int*' to `int**' in assignment

Well, to match, you need to lose the * in the definition, too.

Dynamic Memory - C++ Documentation

However, now I see from your diagram, you want a new array of pointers to a two dimensional array! Can the loop!

filaspointer=new int[fil][col];
1 Like