Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <utility>
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. int main ( )
  7. {
  8. std::string s = "abc";
  9.  
  10. // 1 ok
  11. std::pair < std::string, int > a = std::make_pair ( s, 7 );
  12.  
  13. // 2 error on the next line
  14. std::pair < std::string, int > b = std::make_pair < std::string, int > ( s, 7 );
  15.  
  16. // 3 ok
  17. std::pair < std::string, int > d = std::pair < std::string, int > ( s, 7 );
  18.  
  19. return 0;
  20. }
  21.  
  22. test.cpp: In function ‘int main()’:
  23. test.cpp:11:83: error: no matching function for call to ‘make_pair(std::string&, int)’
  24. test.cpp:11:83: note: candidate is:
  25. In file included from /gcc4.7/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0/utility:72:0,
  26. from test.cpp:1:
  27. /gcc4.7/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_pair.h:274:5:
  28. note: template<class _T1, class _T2> constexpr std::pair<typename std::__decay_and_strip<_T1>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&)
  29. /gcc4.7/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0/bits/stl_pair.h:274:5:
  30. note: template argument deduction/substitution failed:
  31. test.cpp:11:83: note: cannot convert ‘s’ (type ‘std::string {aka std::basic_string<char>}’) to type ‘std::basic_string<char>&&’
  32.  
  33. template <typename T, typename U>
  34. [return type] make_pair(T&& argT, U&& argU);
  35.  
  36. [return type] make_pair(std::string&& argT, int&& argU);
  37.  
  38. make_pair(s, 7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement