Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is a C++ Vector called a Vector?

Tags:

c++

stl

vector

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.

like image 289
Skilldrick Avatar asked Sep 29 '22 00:09

Skilldrick


2 Answers

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.

like image 253
Mark Ruzon Avatar answered Oct 16 '22 12:10

Mark Ruzon


Mathematical definition of a vector is a member of the set Sn, which is an ordered sequence of values in a specific set (S). This is what a C++ vector stores.

like image 125
mmx Avatar answered Oct 16 '22 14:10

mmx