I have been using vector for ages. It is really simple and easy to understand. I could write a whole book on vector, even the implementation is straight forward. This article is just a small glimpse into the code, but it will give you a good look at vector.
What’s not so clear is the implementation.
c++ vector is a vector class. This means that you write a vector class in C++ and use it to create vectors of some other class. Its main purpose is to hold (or create) a collection of objects, but it also has methods that allow you to push things back, pop things back, or access the elements of a single vector object. This gives you a lot of options for creating your vector class.
Vector is so useful to us because we work in c/c++ and we need a bunch of vectors everywhere. But its implementation is so convoluted that it really gives you a headache when you start playing.
I see a lot of people playing with vectors in c++ and not writing their own. Here’s the reason: The compiler has no problem creating a vector of ints, but it can’t create a vector of some other int type. The compiler doesn’t have a mechanism for that either. So instead what we do is we create a vector of some type that we happen to like and that the compiler can’t handle.
The C++ standard library and its vector classes are very complicated. It only took me a few minutes to figure out a few things about the vectors and how they work. It’s not a lot of fun.
Vector classes are an extension to the standard library that create a vector that is a bit more efficient than using an array of ints. They are basically a smart pointer that can take a reference to a larger object, and then it can be used to store that larger object (or a copy of it) in a much more efficient way.
The code I’m writing to explain this is quite simple. In fact, a simple vector class can be a lot of fun in a single line, and it can be useful for creating a few basic vectors.
The first thing we do is create a vector of some size with a default constructor. Once we do this, we create a pointer to the object we want. We then create a copy of this object and store it in the vector. Finally, we create a copy of this object and store it in our vector.
In the past, I’ve always been a huge fan of using a standard container as our container of choice. Like an array or a map, a vector is a container that you can use to store any kind of data you want. We can make our own container with less overhead and less risk, but it’s still very useful.