The choice to use references or pointers is a design decision, it's not a matter of one being better than the other.
The question is, can Boots (conceptually) rebind to a different Cat? If it can, you implement that relationship using a pointer, if it can't you implement that relationship using a reference.
i'd appreciate help with these issues myself, but if there is a memory leak in the first example (which i believe too) then it could be avoided by deleting "pCat" in the makeCat function, i think.
The Object returned still exists in the main - scope and the example still works.
Anyway,in example two, an Object of type CAT is constructed and the adress is returned to "main". If the Object is deleted in makeCAT, it will not work (although it might compile) ... if i'm not right, please notify.
But in this case, when is the Object deleted ??
The destructor for CAT must be called automatically to avoid a memory leak here.
My question: Is that the case ? "Boots" is still created dynamically .... i'm confused.
Is there any resolution in this case? I think that i have to place the "delete pPointer" line at somewhere in the code, but where? still cant determine it.