I just had a go at overloading the + operator. It works, but I want it to do more if possible. For example if i do this in my code:
Code:
String something("strings");
something + " together";
It concatenates the two, but if I do:
Code:
String something("strings");
"I want to put " + something;
It wont work. Is there any way I can get what side of the operator the constant char pointer is on and whack it on the string accordingly?
Heres my function so far:
Code:
String &String::operator+(const char *add)
{
char *origin = str_ptr;
size+=strlen(add);
str_ptr = new char[size];
char *src = origin;
char *dst = str_ptr;
while(*src) *dst=*src, src++, dst++; //Copy original
while(*add) *dst=*add, add++, dst++; //Copy string to add
++*dst='\0';
delete[] origin;
return *this;
}