Need help with an array of a pointer...
void Yaddayadda(int times)
{
Blabla *pBlabla[times];
}
Why isn''t it possible to compile the code above? The compiler (VC++) just says that it''s not a constant expression (error C2057: expected constant expression).. Is there another way of doing it?
cause you can''t declare an array with a non-constant expression like ''int times''
using a constant or using the new and delete operators are among the easy ways to solve your prob
using a constant or using the new and delete operators are among the easy ways to solve your prob
It should work with this:
void Yaddayadda(int times)
{
Blabla **pBlabla;
pBlabla = new Blabla[times];
}
I guess...
void Yaddayadda(int times)
{
Blabla **pBlabla;
pBlabla = new Blabla[times];
}
I guess...
Hmm.. if I compile the code below(inside a class) it compiles fine, but then hangs... Maybe I've missunderstood it?
Blabla **pBlabla; (inside the class)
void Something(int times)
{
*pBlabla = new Blabla[times];
for(int h=0;h!=times;h++)
{
pBlabla[h] = new Blabla(direction,posX,posY);
}
}
Edited by - Jimbo on 3/5/00 6:44:54 AM
Edited by - Jimbo on 3/5/00 6:46:22 AM
Edited by - Jimbo on 3/5/00 6:47:14 AM
Blabla **pBlabla; (inside the class)
void Something(int times)
{
*pBlabla = new Blabla[times];
for(int h=0;h!=times;h++)
{
pBlabla[h] = new Blabla(direction,posX,posY);
}
}
Edited by - Jimbo on 3/5/00 6:44:54 AM
Edited by - Jimbo on 3/5/00 6:46:22 AM
Edited by - Jimbo on 3/5/00 6:47:14 AM
...see if this work:
Blabla **pBlabla; (inside the class)
void Something(int times)
{
pBlabla = new (Blabla*)[times];
for(int h=0;h!=times;h++)
{
pBlabla[h] = new Blabla(direction,posX,posY);
}
}
i''m still learning
Blabla **pBlabla; (inside the class)
void Something(int times)
{
pBlabla = new (Blabla*)[times];
for(int h=0;h!=times;h++)
{
pBlabla[h] = new Blabla(direction,posX,posY);
}
}
i''m still learning
This is how I would do it:
I hate non-dynamic arrays
===============================================
I saw a man pursuing the horizon;
Round and round they sped. I was disturbed at this; I accosted the man.
"It is futile," I said, You can never -- "
"You lie," he cried, And ran on.
void YaddaYadda( int times ){ // create a pointer to a pointer, essentially a pointer to an array of pointers BlaBla **pBlabla = 0; // create the first array. pBlabla = new BlaBla* [ times ]; // you now have an array of BlaBla pointers. // fill them with whatever you want. // NOTE: They are un-initialised, stray pointers.}
I hate non-dynamic arrays
===============================================
I saw a man pursuing the horizon;
Round and round they sped. I was disturbed at this; I accosted the man.
"It is futile," I said, You can never -- "
"You lie," he cried, And ran on.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement