1

Possible Duplicate:
Variable length arrays in C++?

I am just curious, is there any particular reason why C++ does not allow variable length arrays?

Community
  • 1
  • 1
Alexander Rafferty
  • 6,134
  • 4
  • 33
  • 55

3 Answers3

4

Two reasons:

  1. C++ is based on C89 (the C standard as published in 1989). VLAs were only introduced in C99.
  2. C++ has std::vector<> and a whole bunch of other containers, which is why I believe that C++ will never bother with VLAs. It already had them when VLAs were invented for C.
sbi
  • 219,715
  • 46
  • 258
  • 445
2

What about std::vector?

edit: sorry I missundertood your question.

mip
  • 8,355
  • 6
  • 53
  • 72
0

The STL includes a Vector class to use. Technically, you could use an array whose index variable is a pointer, leading to a "variable length" array.

Madison S
  • 225
  • 1
  • 10
  • I understand your second point to refer to dynamic arrays. But C has had these, too, from the very beginning. – sbi Sep 23 '10 at 21:33