ok so we decided that if you were to return a reference u would have to use new within the function. So why is that not ok. Consider this.....
Code:
text& operator + (const text& Text1,const text& Text2)
{
text* NewText=new text;
// concat Text1 and Text2
return *NewText;
}
now what happens when we add these text objects together.
Code:
text T1("foo");
text T2("bar");
text T3("wont");
text T4("do");
text T5;
T5=T1+T2+T3+T4;
How many temporary objects are created in that last expression and who called delete on the newed memory they contain??
That is why operator + MUST return an object. A reference is never suitable.