New
operator is often confusing for me, and using it can lead to memory leaks if I forget to use delete
. Every time I have to allocate an array of objects without knowing its length at compile time, I just use std::vector
. What is the point of using new
?
Also, why would I need to use new
operator to allocate space for just one single instance of an object?