Why is a C++ Vector called a Vector?

后端 未结 16 2367
情话喂你
情话喂你 2020-12-04 07:42

The question\'s pretty self-explanatory really. I know vaguely about vectors in maths, but I don\'t really see the link to C++ vectors.

相关标签:
16条回答
  • 2020-12-04 07:59

    It's called a vector because Alex Stepanov, the designer of the Standard Template Library, was looking for a name to distinguish it from built-in arrays. He admits now that he made a mistake, because mathematics already uses the term 'vector' for a fixed-length sequence of numbers. C++11 compounds this mistake by introducing a class 'array' that behaves similarly to a mathematical vector.

    Alex's lesson: be very careful every time you name something.

    0 讨论(0)
  • 2020-12-04 08:01

    The name comes from the linear algebra, where vector is matrix with only one column or only one row.

    0 讨论(0)
  • 2020-12-04 08:03

    but mathematical vectors aren't dynamic, I've never seen one change from 2D to 3D or anything else, if anything traditional arrays make for better vectors.

    0 讨论(0)
  • 2020-12-04 08:04

    it comes from the structure of matrix which build from vectors

    0 讨论(0)
  • 2020-12-04 08:05

    I'd guess it comes from the term row vector. Also, computer scientists love thinking up new names for things...

    0 讨论(0)
  • 2020-12-04 08:06

    A vector is simply a sequence of values, all of the same type. This is pretty much in line with the use in mathematics. I guess the mathematical idea that vectors should support some common operations (such as adding, and scaling by a scalar) are not carried over, the important aspect is mainly the structure.

    0 讨论(0)
提交回复
热议问题