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,850
  • 9
  • 56
  • 64
abbas
  • 143
  • 1
  • 2
  • 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
  • 151,563
  • 33
  • 264
  • 304
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
  • 76,846
  • 14
  • 164
  • 167