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.
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.
the string class manages its memory for you. You don't have to delete memory for string objects in the destructor.
You're only born perfect.
>In the destructor do i have to do anything special for the string?
No
>i tried delete name_of_string and the compiler complains that delete wants pointer.
Only use delete when you use new. For every new, you need a delete.
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.