allocating an array of pointers dynaically
How would I do this?
I have a var: float **ins; that I want to hold an array of pointers to floats. How can I do this using the new command?
My initial thought was to do soething like:
ins = new (float*)[numofins];
but the compiler doesn''t like that at all
I did look in MSDN btw, and I found how to do it like this:
float *ins[3];
but that doesnt help much
thanx!
tazzel3d ~ dwiel
you were almost right what you actually want is ins = new float *[number of float pointers];
eg
to initialise the pointers in the array you could do
[edited by - vivi2k on September 19, 2002 8:48:21 AM]
eg
float **a;a = new float *[20];
to initialise the pointers in the array you could do
for(int i = 0;i < 20; i++){a = new float[whatever u like];}
[edited by - vivi2k on September 19, 2002 8:48:21 AM]
quote: Original post by vivi2k
for(int i = 0;i < 20; i++)
{
a = new float[whatever u like];
}
lol, stupid vb tags it becomes italic :D
anyway, it's not a = new float[whatever u like];
but:
for (int index_i=0; i<20; i++){ a[index_i] = new float [whatever u like];}
when you do this:
a = new float* [20];
you make 20 pointers, which are not yet initialized, to float data type. These pointers need to be valid, so you initialize each of them:
a[0] = new float [whatever u like];a[1] = new float [whatever u like];... // and so on until index 19
something like that.
My compiler generates one error message: "does not compile."
EDIT:
Arghh!! Damn tags!
[edited by - nicho_tedja on September 19, 2002 6:07:18 PM]
My compiler generates one error message: "does not compile."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement