destructor class function

I need to build destructor class function for this but i dont know how.
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>
using namespace std;

class node {
public:
	string name;
	node *next;
	node(string input) {name = input; next = NULL;};
    
};


for string class it was
1
2
3
4
~Stirng();
Stirng::String(){
delete [] ptr;
}


but for this i dont know
Firstly, the destructor you posted doesn't have ~, though that might have been a typo.

Do you need to delete next ? I don't see where the problem is..
Revise the example so that it destroys nodes upon exit. this is what i must do.
Well, then write a destructor and put delete next; in it. If you don't know how to write one, see http://www.cplusplus.com/doc/tutorial/classes/ (around middle)
Last edited on
so basiclly. ~node() {delete next;}
or what?
Pretty much yes, just be sure you don't delete memory thats not yours (NULL/Uninitialized)
well then giveme a code that only deltes the memory used by this program.
Wouldn't you gain more from it if you figured it out on your own?
true, but my comp is already pretty fucked up, so i dont wanan fuck it up even more.
'comp' is short for what?
Your code is fine. Whether you have any problems with it depends on how you use it.
comp as i computer
You can't fuck up your computer this way.
Do your own homework
not a homework. self study. school doesent teach this.
Topic archived. No new replies allowed.