In this question the OP explores the idea of a function which returns a reference on a dynamically created object.
intArray& createArray()
{
intArray *arr = new intArray(10000, 0);
return(*arr);
}
The answers are that even dough this will compile, it will confuse the programmer who is using the function. He will be confused because it is expected that when a function returns a reference, the 'user' of that reference isn't responsible for its memory management.
I have noticed that there are lots of API methods which return pointers. Does that imply that I'm responsible for clearing (deleting the object and setting the pointer to NULL) them once they aren't needed any more?