When to use “new” and when not to, in C++?

You should use new when you wish an object to remain in existence until you delete it. If you do not use new then the object will be destroyed when it goes out of scope. Some examples of this are: Some people will say that the use of new decides whether your object is on the heap or the stack, but that is … Read more

creating an array of object pointers C++

Will it work? Yes. However, if possible, you should use a vector: If you have to use a dynamically allocated array then I would prefer this syntax: But forget all that. The code still isn’t any good since it requires manual memory management. To fix that you could to change your code to: And best … Read more