Can you tell me, what is exactly behind of this following problem? This code is a simple example working on c++03 and fails on c++11.
std::pair<int*,int**> getsth(int* param)
{
return std::make_pair<int*,int**>(param, 0);
}
int main(int argc, char* argv[])
{
int* a = new int(1);
std::pair<int*,int**> par = getsth(a);
std::cout << *par.first;
return 0;
}
I do know how to fix it to be compatible with both standards here, but it is annyoing me, that I don't know, what is exactly behind make_pair in this case.
Thanks!
edited: a compile error message from Coliru:
main.cpp: In function 'std::pair<int*, int**> getsth(int*)':
main.cpp:8:47: error: no matching function for call to 'make_pair(int*&, int)'
return std::make_pair<int*,int**>(param, 0);
^
main.cpp:8:47: note: candidate is:
In file included from /usr/local/include/c++/4.9.2/bits/stl_algobase.h:64:0,
from /usr/local/include/c++/4.9.2/bits/char_traits.h:39,
from /usr/local/include/c++/4.9.2/ios:40,
from /usr/local/include/c++/4.9.2/ostream:38,
from /usr/local/include/c++/4.9.2/iostream:39,
from main.cpp:1:
/usr/local/include/c++/4.9.2/bits/stl_pair.h:276:5: note: template<class _T1, class _T2> constexpr std::pair<typename std::__decay_and_strip<_Tp>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&)
make_pair(_T1&& __x, _T2&& __y)
^
/usr/local/include/c++/4.9.2/bits/stl_pair.h:276:5: note: template argument deduction/substitution failed:
main.cpp:8:47: note: cannot convert 'param' (type 'int*') to type 'int*&&'
return std::make_pair<int*,int**>(param, 0);
^
main.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type]
}
Aucun commentaire:
Enregistrer un commentaire