I\'ve been using C++ for a short while, and I\'ve been wondering about the new keyword. Simply, should I be using it, or not?
1) With the new keywo
Method 1 (using new)
delete your object later. (If you don't delete it, you could create a memory leak)delete it. (i.e. you could return an object that you created using new) deleted; and it should always be deleted, regardless of which control path is taken, or if exceptions are thrown.Method 2 (not using new)
delete it later.return a pointer to an object on the stack)As far as which one to use; you choose the method that works best for you, given the above constraints.
Some easy cases:
delete, (and the potential to cause memory leaks) you shouldn't use new.new