When I was having a go with std::string
, I decided to do the following:
int main(int argc, char **argv)
{
std::string s = "Hello World";
s.~basic_string();
std::cout << s.c_str();
}
However, it prints nothing, and there is no garbage. However, in my basic_string
class, when the destructor is called, I get garbage. How does the std::string
handle this? Mine uses an allocator
and construct
s, destroy
s, allocate
s and deallocate
s, yet it still doesn't work.
Note: I'm not looking for a solution to my class, but to find out how std::string
does it.