|
From: | Thomas Maeder |
Subject: | Re: Newbie question: The correct way to delete a pointer array to a pointer array |
Date: | Fri, 25 Feb 2005 22:08:26 +0100 |
User-agent: | Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
Thomas <tlann@technoeclectic.com> writes: > I'm using the following > char** m_pcPuzzle; > > to create an array for to store a crossword puzzle. I allocate memory > using the next few lines > > //allocate memory for new map > m_pcPuzzle=new char*[m_iWidth]; > > for (int x=0;x<rhs.m_iWidth;x++) > m_pcPuzzle[x]=new char[m_iHeight]; > > > What is the correct way for me to call delete? > > Should I just do > > for (int x=0;x<m_iWidth;x++) > delete m_pcPuzzle[x]; This has to read delete [] m_pcPuzzle[x]; > delete [] m_pcPuzzle; > > Am I allocating the memory correctly? Unless you have *very* good reason not to, use std::vector and std::string.
[Prev in Thread] | Current Thread | [Next in Thread] |