fork download
  1. #include <map>
  2. #include <iostream>
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6. std::map<int, int&> m;
  7. int x = 0;
  8.  
  9. //m[0] = x; //error
  10. m.insert(std::pair<int, int&>(0, x));
  11.  
  12. //ちゃんと参照を保持している
  13. x++;
  14. std::cout << m[0] << std::endl;
  15.  
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0.02s 2860KB
stdin
Standard input is empty
stdout
1