I have an assignment about the String Class overload function and operator.
Here is the problem i face:
Need an append() function to construct the String.
So the String constructor is:
String::String(char *s)
{
init();
append(s);
}
String& String::append(char *other)
{
String temp;
temp.m_length=strlen(other)+strlen(temp.m_buffer)+1;
temp.m_buffer=new char[] m_length;
if(!m_length)
{
strcpy(temp.m_buffer,other);
return temp;
}
else
return temp;
}
So the compiler passing it but no correct result?
So here's append() is similar to operator +=??
Here is the assignment:
Consider what the return value should be. You should be able to write code like:
String s1 = "foo";
String s2 = "bar";
s1.append (s2);
now s1 is "foobar"
String s3 = "moo";
s3.append ("quack").append ("meow");
now s3 is "mooquackmeow"
Anybody knows how to do that append() function??
thanks so much