c++ - Operator New in function call -
void f(a* a) { delete a; }; f(new a()); will delete operator release allocated memory or must create , delete object this:
f(a* a) {} a = new a(); f(a); delete a;
yes free memory, preferred use smart pointers such std::shared_ptr or boost::shared_ptr prior c++11 instead. in example better set freed pointer null avoid double deallocation avoiding dangling pointer errors.
void f(a*& a) { delete a; = null; }; you not able call f(new a()); thru , require pass reference pointer holding variable. in 2nd variant. there should a* = new a(); there thru, indicate a pointer.