以下程序的輸出...模板構造函數優先於普通副本並移動構造函數?
#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);
}
是
tmpl
tmpl
所需的輸出是:
tmpl
copy
爲什麼沒有具體的拷貝構造函數優先於模板構造函數?
有沒有辦法修復它,以便複製和移動構造函數重載將優先於模板構造函數?
這裏是與這個問題有關的最終課程:http://codereview.stackexchange.com/questions/20058/a-c11-any-class –