So I'm lurking in posts, trying to collect every bit of knowledge here and there to improve my overall C++ knowledge/skills. Yesterday I found the following comment:
In modern C++ avoid raw pointers, memory management, new and delete. Instead use smart pointers (std::unique_ptr and std::shared_ptr), STL containers all of which use RAII concepts.
I'm super sorry, can't remember who commented this and where(couldn't find it) so I can't talk with the person.
If this is true (which I assume is) why? I mean why should we avoid raw pointers, memory management, new and delete in modern C++?
avoid raw pointers, memory management, new and delete
I think the commas are wrong. What I hope it tries to say is that you should avoid using raw pointers for memory management. Raw pointers can still be useful sometimes. Sure, you shouldn't use them without reason, but they still serve a purpose, similar to iterators. Just don't use them to declare ownership.
It was in response to the OP wanting to use buffers with pointers and offset when they already had an STL container, and about them not to think in C, instead C++.
What Peter87 is saying is exactly right, but I meant that one could go a long way using the STL, references, smart pointers, range based for loops and iterators - without ever needing to use a raw pointer.