0
Point V[rows];

Is this allowed in C++? rows is a variable whose value is given at runtime and Point is my class.

Smi
  • 13,151
  • 9
  • 55
  • 63
abbas
  • 133
  • 1
  • 1
  • 8

2 Answers2

4

In C++ the comparable idiom is:

std::vector<Point> V(rows);

It's not 100% identical, because it still calls new Point[] (c99 can use the stack), but it still gives you the vector without performing multiple allocs.

SingleNegationElimination
  • 144,899
  • 31
  • 254
  • 294
0

Only in C99 - it's a new feature called "variable length arrays". Normally, no.

I would strongly recommend against using this feature. If you have to do it, either use alloca, or allocate them properly, i.e. Point *V = new Point V[rows];.

BTW: Many people discourage Alloca as well. See here.

Community
  • 1
  • 1
EboMike
  • 75,005
  • 14
  • 154
  • 164