Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. Why does this not compile:
  2. #include <iostream>
  3.  
  4. std::string getString() {
  5. return std::string("Hi");
  6. }
  7. int main() {
  8. std::string& s = getString();
  9. std::cout << s << std::endl;
  10. }
  11.  
  12. but this does:
  13. #include <iostream>
  14.  
  15. std::string getString() {
  16. return std::string("Hi");
  17. }
  18. int main() {
  19. const std::string& s = getString();
  20. std::cout << s << std::endl;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement