参照微软官方回复:
#include <iostream>
#include <ostream>
#include <string>
#include <utility>
using namespace std;
int main() {
string ht = "hello";
pair<double, string> ps;
#if defined(FIX1)
ps = pair<int, string>(1, ht);
#elif defined(FIX2)
ps = make_pair(1, ht);
#else
ps = make_pair<int, string>(1, ht);
#endif
cout << ps.first << " " << ps.second << endl;
}
C:\Temp>cl /EHsc /nologo /W4 kitty.cpp && kitty
kitty.cpp
kitty.cpp(16) : error C2664: 'std::make_pair' : cannot convert parameter 2 from 'std::string' to 'std::string &&'
You cannot bind an lvalue to an rvalue reference
C:\Temp>cl /EHsc /nologo /W4 kitty.cpp /DFIX1 && kitty
kitty.cpp
1 hello
C:\Temp>cl /EHsc /nologo /W4 kitty.cpp /DFIX2 && kitty
kitty.cpp
1 hello
Both FIX1 and FIX2 construct a temporary pair<int, string>, which is then converted during assignment to pair<double, string>.
I personally recommend FIX2.
https://connect.microsoft.com/VisualStudio/feedback/details/691756/std-make-pair-error-in-vc11