Question

i get this error at the constructor of my struct. why do i get it sincei work only with * pointers not **.

Error:

\ListStruc.cpp:26:25: error: cannot convert 'int**' to 'int*' in assignment

struct.h

struct Arr{

    int days;
    int *M;
};
typedef Arr* Array;

struct.cpp

void constr(Array &o){
    //Construct of 1*31 Matrix
    o=new Arr;
    o->days = days;
    o->M = new int*[o->days];
Was it helpful?

Solution

Since M is an int*, the correct initialization would be:

o->M = new int[o->days];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top