I have an overloaded ~ operator...which returns a temp object...which I can't get around because that's the way my professor would like. I have an assignment operator for objects as well....basically I have the call..... t21 = ~s21. But when t21 goes to assign s21 to it, there's nothing in the member buf because it got ran through the deconstructor.... (I think)... So I'm at a wall with my limited knowledge. Any thoughts....(besides not returning temp objects)...
Code:
ReverseString ReverseString::operator~()
{
int size = m_length;
int i;
int j;
char* temp = new char[size];
for(i = m_length - 1, j = 0; i >= 0; i--, j++)
{
temp[j] = m_buf[i];
}
temp[size] = '\0';
ReverseString rev(temp);
return rev;
}
ReverseString& ReverseString::operator=(const ReverseString& rhs)
{
if(this == &rhs)
{
return *this;
}
m_length = rhs.m_length;
if(NULL != m_buf)
{
delete[]m_buf;
m_buf = NULL;
}
m_buf = new char[m_length + 1];
strcpy_s(m_buf, m_length + 1, rhs.m_buf);
return *this;
}
This will be one of my last posts as I'm graduating in three weeks....and I still don't know anything...LOL!!!!