Because a normal instance will get destroyed when out of scope. Pointers don't get "destroyed", only their identifier will be destroyed when they go out of scope (the way you refer to them, like, in your first example, s is the identifier) - the actual instance stays intact. That's the reason pointers are chosen; they refer not to an instance, but to the memory address of an instance.
One more thing, Am I to understand that the constructor for a type like this, string in this case returns string*. Is there a way to see this implementation ? (although I tend to believe not, because constructors have no return types, right?)
I am doing an exercise on this very topic and have a follow-up question. I hope I get some replies despite the thread being flagged as solved.
So, using the example of the OP, string *s = new string yields a pointer called s to the address containing a string initialized to a default value. Whereas, string s = string yields a string called s initialized to the value 'string'.
My questions are, in the first case, does the object pointed to by s have a name? Can I refer to that object without using the pointer?
My questions are, in the first case, does the object pointed to by s have a name? Can I refer to that object without using the pointer?
No.
When using the term "name" loosely, you could say that its address is its name which you can use to refer to it.
But if you forget that name (=its address=the pointer), you no longer can, of course.