In java, to make a function that returns an object that is the same type as a parameter and extends a certain class, I would type:
Since I can't comment on the accepted answer, I'm providing a new answer which builds on it.
The template parameters can be simplified by having the enable_if condition become the default type template parameter instead of nullptr.
enable_if
nullptr
template::value>>