Will this lead to a memory leak in C++?
问题 I have a C++ memory management doubt, that's (obviously) related to references and pointers. Suppose I have a class Class with a method my_method : OtherClass& Class::my_method( ... ) { OtherClass* other_object = new OtherClass( ... ); return *other_object; } Meanwhile in a nearby piece of code: { Class m( ... ); OtherClass n; n = m.my_method( ... ); } So, I know that there's a general rule about pointers (~ "anything new-ed, must be delete-d") to avoid memory leaks. But basicly I'm taking a