[SOLVED] Segfault (pol1)

Hey,

I'm getting a segfault with the following code:
1
2
3
4
5
6
7
8
int indx = enigma::room_idmax++;
enigma::roomstruct** newroomdata;
     
newroomdata = new enigma::roomstruct*[indx + 1];  

printf("e");    
newroomdata[indx]->id = indx;
printf("f");

It's printing e but not f so it's segfaulting at newroomdata[indx]->id = indx;

Can anybody see anything I have done wrong with the pointers or array size? Thanks for any help.

roomstruct is declared like so:

1
2
3
4
5
6
7
namespace enigma
{
  struct roomstruct
  {
    int id;
  };
}
Last edited on
Nevermind I solved it. I needed to use:

newroomdata[indx] = new enigma::roomstruct;
Topic archived. No new replies allowed.