C++ runtime error?
Point V[rows];
Is this allowed in C++? rows
is a开发者_JS百科 variable whose value is given at runtime and Point
is my class.
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.
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.
精彩评论