0

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];
Bogdan Maier
  • 663
  • 2
  • 13
  • 19

1 Answers1

3

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

o->M = new int[o->days];
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • thanks >.> how can i init the array with objects of a class i get error int cant be converted to Expre, expe beeing my class. – Bogdan Maier Apr 11 '12 at 19:53
  • @BogdanMaier I literally didn't understand anything you just said. – Luchian Grigore Apr 11 '12 at 20:03
  • i fixed the error. Now i`m looking forward to make that array, an array of class objects were do i have to declare in the constructor/header that or how should i do it since classes arent types and i have no clue how should i do that? – Bogdan Maier Apr 11 '12 at 20:22
  • @BogdanMaier you could ask another question. be sure to include new code that you're trying to write. btw classes are types. the only difference between struct and class is class members are private by default. – Will Ness Apr 11 '12 at 20:26
  • @BogdanMaier maybe you should ask a new question with the code you have now and what you want to achieve. – Luchian Grigore Apr 11 '12 at 20:26