以下のコードでは:
template<class Key, class Value>
class Pair
{
private:
std::pair<Key,Value> body_;
public:
//No cpy ctor - this generated by compiler is OK
Pair(Key&& key,Value&& value)
{
body_.first = key;
body_.second = value;
}
Pair(Pair<Key,Value>&& tmpPattern)
{
body_.swap(tmpPattern.body_);
}
Pair& operator=(Pair<Key,Value> tmpPattern)
{
body_.swap(tmpPattern.body_);
return *this;
}
};
template<class Key, class Value>
Pair<Key,Value> MakePair(Key&& key, Value&& value)
{
return Pair<Key,Value>(key,value);
}
MakePair を実行しようとすると、奇妙な理由でエラーが発生します。なぜですか? 神のみぞ知る...
int main(int argc, char** argv)
{
auto tmp = MakePair(1, 2);
}
これは次のエラーです:
エラー エラー C2665: Pair::Pair' : none of the 3 overloads could convert the all argument types
どの変換を実行する必要があるのか わかりませんか?