I understanding that a new object is being created on the heap, and a pointer to it is being returned. But I don't understand why this code is valid, and I feel I should before moving on! The function is not returning a pointer, it is returning an object. What exactly is happening in order for the code to be valid?
The (*this) referred to here is a parameter for a copy constructor...
Or is that not the pointer you are referring to? Do you mean another pointer which is provided as a result of creating the new Cat on the heap? Is there a conversion going on as a result of the return type?
lol clearly this will need to be spelt out a little :P
Your new object of cat is being created and its pointer is being returned (through Mammal* return type)...how could it possibly return an Object wen the return type is of pointer? Its not possible!
@zuluisgrate:
You might be confused by the "*this", which is an object (a dereferenced pointer to an object, thus an object). However, the *this is simply a parameter for the constructor. The returned thing is actually the return value of "new Cat(<params>)", which is a Cat* (pointer!). Conceptually no different from doing "return new Cat(5);", but perhaps less confusing to look at.