There is a lot to talk about here.
Basically a
std::vector
has 2 things: a size and a pointer to the memory which was allocated with
new
, so the data is on the heap. The actual details are a bit complicated, and requires knowledge of templates and Template Meta Programming (TMP), and exceptions.
The whole idea of the Standard Template Library (STL) is to make life easier for coders. The least of it is not having to do manual memory management, and being able to dynamically resize containers with little effort nor knowledge of what the compiler does implicitly. The STL has RAII, move semantics, and has a lot things which make it behave very well.
One of the problems with people new to C++, is that they often think in C not C++. It's an easy trap to fall into, not meant to be a criticism :+) This a big problem problem because people approach things at too low a level, such as wanting to do things with pointers, as opposed to all the good stuff that comes with the STL. There is a school of thought that says: to teach C++,
don't teach them C !
C++ is a multi paradigm language: one can do C style programming; use the STL; do OOP with classes and virtual polymorphism etc; and do template programming and TMP. But doing C style coding when the STL is available is discouraged.
It is possible to do multiple dimension arrays with pointers, it's just the same as in C. But that is tricky to get right, so use an STL container.
Also, using
std::vector<std::vector<TYpe>>
gives a ragged array because the inner vector size can vary. There is also
std::array<std::array<Type>>
, but one must specify the size at compile time. Also could use
std::vector<std::array<Type>>
if that suits you better.
Not sure if you have seen these:
https://stroustrup.com/bs_faq2.html
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
There was also an article by Stroustrup about the details of RAII, but I couldn't find it.