string destructor

This is a discussion on string destructor within the C++ Programming forums, part of the General Programming Boards category; In a class i have many string (#include <string>) variables. In the destructor do i have to do anything special ...

string destructor

In a class i have many string (#include <string>) variables. In the destructor do i have to do anything special for the string? i tried delete name_of_string and the compiler complains that delete wants pointer.

That's one of the wonderful thing about such classes in the STL. Internally, all memory of a std::string is managed for you. That's why you can do a std::string s = "blah"; without calling new. A rule of thumb to keep in mind is that you should call delete exactly once for every call to new, and since you never call new for a string the way you're using it, you should never try to delete it.