do I need to destroy a string in c++

Yes, std::string's resources are cleaned up automatically. Standard strings and containers allocate/deallocate for you. HOWEVER, a container of pointers doesn't free up what those pointers point to. You have to loop through those yourself.


No. The string's destructor will be called once an instance of A goes out of scope.


You're not creating a pointer to the string, so Test will be allocated onto the stack (Assuming object A was allocated onto the stack). Thus, when it leaves scope, it will be deallocated automatically. If Test were a pointer it would be allocated on the heap and you would need to delete it in the destructor

Tags:

C++

Stl