Thanks for your reponse! You said " When the original string object is deleted, your “copied” one will contain a dead pointer". I wander when that the original string object is deleted happens? It looks like no variables are out of scope. Thanks for your inputs.
Quote Originally Posted by VladimirF View Post
One obvious problem is that secure version of strcat() requires the available size of destination string to prevent buffer overrun; you are passing the “desired” size, which no one allocates.
In your main function, the constructor:
Code:
s1("Hi");
will allocate exactly 3 chars, with no room for concatenation. So this line:
Code:
s2 = s1 + " there";
will write outside of allocated memory (undefined behavior; likely – crush).
Also, don’t you need to implement an assignment operator for your string? The one generated by compiler will copy your member variables (char* m_str). When the original string object is deleted, your “copied” one will contain a dead pointer.