Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why does this not compile:
- #include <iostream>
- std::string getString() {
- return std::string("Hi");
- }
- int main() {
- std::string& s = getString();
- std::cout << s << std::endl;
- }
- but this does:
- #include <iostream>
- std::string getString() {
- return std::string("Hi");
- }
- int main() {
- const std::string& s = getString();
- std::cout << s << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement