Say I have a template class
template<typename T>
class Foo {
template<typename U>
Foo(const Foo<U> &foo) {
...
}
}
Obviously, Foo<T>(const Foo<T>&)
is an instance of that template member, but for some reason C++ chooses to use the implicit copy constructor instead of instantiating this copy constructor from the template.
Is there a way to force the copy constructor to be instantiated from the template?
Usually, something like
template<> template<> Foo<int>::Foo(const Foo<int>&);
would work if I want a specific instance, but I want every Foo<T>
that gets instantiated to also have Foo(const Foo<T>&)
be instantiated as well.
How can I achieve this?
Without actually writing out Foo::Foo(const Foo&);
separately, using the same exact code, of course. That would be silly.