8
The output of the following program...
#include <iostream>
using namespace std;
struct X
{
X(const X&) { cout << "copy" << endl; }
X(X&&) { cout << "move" << endl; }
template<class T> X(T&&) { cout << "tmpl" << endl; }
};
int main()
{
X x1 = 42;
X x2(x1);
}
is
tmpl
tmpl
The desired output is:
tmpl
copy
Why doesn't the concrete copy constructor take precedence over the template constructor?
Is there anyway to fix it so that the copy and move constructor overloads will take precedence over the template constructor?