I'm trying to write a simple version of the string class (for practice), and I have everything working except the overloaded + operator.
The line " strcpy_s(temp, strlen(stringPtr) + 1, stringPtr); " keeps throwing an exception. I assume strcat_s will too.
Any advice?
MyString MyString::operator+(const MyString & other)
{
if (this != &other)
{
char * temp = new char[strlen(stringPtr) + strlen(other.stringPtr) + 1];
strcpy_s(temp, strlen(stringPtr) + 1, stringPtr);
strcat_s(temp, strlen(other.stringPtr) + 1, other.stringPtr);
delete[]stringPtr;
stringPtr = temp;
delete[]temp;
}
return this->stringPtr;
}
If it helps, stringPtr is being passed "bob," and other.stringPtr is being passed "sally."