I'm trying to write a destructor function for my class type message, but I can't get the dang thing to delete
strings.
So, uhm, Help!
Do I have to go through a for loop and delete each character individually?
I'm trying to write a destructor function for my class type message, but I can't get the dang thing to delete
strings.
So, uhm, Help!
Do I have to go through a for loop and delete each character individually?
Do I have to go through a for loop and delete each character individually?
No. Just calling delete pointer_variable should suffice. The destructor of class string should handle the rest. If you are trying to delete an array of string pointers, use delete []array_name; Another thing is make sure that you are trying to delete a pointer and not a normal variable.
Can you post the declaration of your class, and it's constructor?
Its also a good practice to make your destructor virtual, and in that way you can be sure that when you start building hierarchies, you dont start wondering where all the memory leaks a coming from (child class object is not automatically destroyed if you dont make destructor virtual).
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.