#include <iostream>
void print_me_bad( std::string& s ) {
std::cout << s << std::endl;
}
int main()
{
print_me_bad( std::string( "World" ) ); // Compile error; temporary object
return 0;
}
I know that putting a const keyword in the print_me_bad function would solve the problem.
But my question is , the temporary object string( "World" ) gets destroyed after we passed its closing paranthesys ( right after "Word" literal)?
and that's why we need a const keyword .
Am I correct ?