Hi All!
I have a doubt about returning reference. I'll show you an example:
Vector &MakeVector()
{
Vector *result = new Vector<Dim>();
/*some more code*/
return *result;
}
now I can call the function MakeVector to assign it result in this two ways:
Vector v = MakeVector(); //first case
Vector *ptrVector; //secound case
*ptrVector = MakeVector();
I have some question about it:
in the first case: do I leave any garbage in the memory?? because I'm creating an object with the new operator, so I think that i have to free it in some place. But I know that in this case is not necessary to call the destructor because the destructor of v is called automatically. So I don't know if I'm leaving garbage in the memory.
in the secound case: I have to call the destructor in order to not leave garbage in the memory. Right ?
thanks before hand!