Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New operator

Status
Not open for further replies.

chikyu

Programmer
Jul 11, 2001
6
JP
Hi all,
if I create a funtion Array2(int,int) which return a matrix and that inside the function I create the array using the NEW operator, do I need to use the DELETE operator to delete the matrix after use?

Thank you for your kind inputs.
 
it should be stated that you have to be careful with your delete calls. they are very necessary but can get a bit tricky. say you pass a pointer to another function, then you delete the object in the original, but it's still needed in the secondary function. you'll get a memory exception. that's a simple multi threaded example. just be careful, but as zyrenthian said, every new should be accompanied by a delete somewhere down the road(even if you dont' call the delete. eg. you use a container class like a CList and you delete the CList or it goes out of scope.. the CList's destructor should call the destructor on all of it's members, and subsequently you wouldn't need to call delete. I'm pretty sure about that, but if not could someone clarify for me?) good luck MYenigmaSELF:-9
myenigmaself@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top