I do not think your code should compile (and it is not in gcc)
std::unique_ptr<Cow> uses std::default_delete<Cow> , and std::default_delete<Cow>::operator() cannot create an instance for the incomplete type Cow .
See also. Is it true that a unique_ptr declaration, unlike an auto_ptr declaration, is well defined when its template type is an incomplete type?
So you are right: you need to make sure that default_delete<Cow>::operator() is created somewhere that the type Cow complete. This means that the Farm destructor must be defined in such a place.
I just noticed that your object says "smart pointer", and the question unique_ptr . The answer will be different for shared_ptr , since std::shared_ptr<Cow>::reset() is a function template that captures the (static) type of the pointer passed to it and saves the debiter. Thus, with shared_ptr all you need is that the reset call has the full Cow type - the location of the destructor does not matter.
Steve jessop
source share