problem with pointers

this code works...
1
2
  int **p=new int*[2];


but can someone help me with the code below?
1
2
    int **p;
    *p = new int*[2];
First off, are you sure you want to make a pointer that points to pointers?
What are you even trying to do?

And second, the reason this doesn't work is in simple terms you are trying to put two int pointers into an array of integers.

when you have
int **p;
This is a pointer that points to a pointer

So in order to allocate space for this you would do
p = new int*[2];


What are you trying to do though? If you don't have a very good understanding on pointers you really should not use them.
thx, it works

I wanted to do this... so I can put a few querymodels in an array in the heap
so I thing I need an array of pointers that point to the querymodel

1
2
3
4
5
6
 
    QSqlQueryModel **model;
    model = new QSqlQueryModel*[2];

    model[0]= new QSqlQueryModel();
    model[1] = new QSqlQueryModel();


I was confused about p in
p = new int*[2];


thx very much
Oh okay I've never worked with that.

Also, don't forget that every time you call new, you need to call delete or else you'll have memory leaks!

Good luck!
Topic archived. No new replies allowed.