cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
The usage of delete
The usage of delete
Nov 26, 2013 at 12:34am UTC
peachgcm
(1)
Hi,
I am wondering in the following context, should I use delete or delete[]? Thanks.
struct node{
int val;
node * lnode;
node * rnode;
};
int main(){
node * nd = new node;
delete nd; or delete[] nd?
}
I have this question because nd has two pointers. Thus I am not sure whether I should use delete or delete[]. Thanks.
Nov 26, 2013 at 1:15am UTC
xismn
(961)
Use
delete
.
Nov 26, 2013 at 1:20am UTC
closed account (
Dy7SLyTq
)
you use delete when you use new and you use delete[] when you use new[]
Nov 26, 2013 at 9:39am UTC
MikeyBoy
(5631)
I have this question because nd has two pointers.
What does that have to do with it?
Note that by deleting an instance of node, you are not automatically deleting the objects that lnode and rnode point to. If you want those to be deleted too, then you'll need to write a destructor that does it.
Topic archived. No new replies allowed.