Different instantiations of a template are unrelated types, even if the instantiating template arguments are related. That is, X<A>
is not related to X<B>
regardless of what the relationship between A
and B
might be.
Now as of what can be done, it depends on what your template actually is. In some cases you can provide conversions so that the X<Derived>
can be converted to a X<Base>
for a particular operation. Another alternative is modifying your function to be able to take any X<T>
for which T
derives from Base
(this can be done by creating a template and using SFINAE to disallow calling it with T
s that don't derive from Base
. Again, depending on what your template is, you might be able to offer access to the underlying type, in which case the function could take a reference to Base
(consider shared_ptr
or unique_ptr
with the .get()
method)
Without a description of what you actually want to get done it is impossible to provide a good alternative.