This is my code.. is giving me a warning saying that 'str' reference to stack memory associated with local variable 'str' returned... Also, I wanna be sure that my logic is good or if there a simpler way to way, I will really appreciate some help to learn more ways.. Thanks!
void CopyString(char *s)
{
delete szArr;
if (s)
{
szArr = new char[strlen(s)+1];
strcpy(szArr,s);
}
else
{
szArr = new char[1];
szArr[0]=0;
}
}
MyString& operator+(char *s){
if (!s)
return *this;
char *tmp=new char[strlen(szArr)+strlen(s)+1];
strcpy(tmp, szArr);
strcat(tmp, s);
MyString str(tmp);
delete tmp;
return str;
}