fork download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. using namespace std;
  5.  
  6. pair<int, int> test() {
  7. return make_pair(13, 42);
  8. }
  9.  
  10. int main() {
  11. int a = 1, b = 2;
  12.  
  13. pair<int&, int&>(a, b) = test();
  14. //make_pair<int&, int&>(a, b) = test();
  15.  
  16. cout << a << ' ' << b << endl;
  17. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/include/c++/4.3/bits/stl_pair.h: In member function 'std::pair<int&, int&>& std::pair<int&, int&>::operator=(const std::pair<int&, int&>&)':
/usr/include/c++/4.3/bits/stl_pair.h:73: error: non-static reference member 'int& std::pair<int&, int&>::first', can't use default assignment operator
/usr/include/c++/4.3/bits/stl_pair.h:73: error: non-static reference member 'int& std::pair<int&, int&>::second', can't use default assignment operator
prog.cpp: In function 'int main()':
prog.cpp:13: note: synthesized method 'std::pair<int&, int&>& std::pair<int&, int&>::operator=(const std::pair<int&, int&>&)' first required here 
/usr/include/c++/4.3/bits/stl_pair.h: In constructor 'std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = int, _U2 = int, _T1 = int&, _T2 = int&]':
prog.cpp:13:   instantiated from here
/usr/include/c++/4.3/bits/stl_pair.h:106: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
/usr/include/c++/4.3/bits/stl_pair.h:106: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
stdout
Standard output is empty