Does a templated constructor (such as the following) override the implicit copy constructor?
template <class T>
struct Foo
{
T data;
// ...
template <class U>
Foo(const Foo<U> &other) : data((T)doSomethingWith(other.data)) {}
// ...
};
If so, does it still override it if other is passed by value rather than constant reference?
If so, is there any way around this without explicitly defining a copy constructor?
No, that is not a copy constructor. Section 12.8 (
[class.copy]) of the Standard requires that:The compiler will still implicitly generate a defaulted one.
You can make that explicit (requires C++11) by