Alex Rivera | Logout

does std::runtime_error copy the string passed in the constructor?

Asked 2012-05-17T23:39:30.803
21

I wonder if this line creates a dangling pointer:

string arg="derp";
throw std::runtime_error("Unknown argument "+arg);

Does std::runtime_error copy the string, or does it store the reference?

Edit
Report

1 Answer

1

it takes a string refrence. And passes that to the catch block as a reference, however if you pass a string litterial into the constructor it will create a temp string object. Also, do not do + arg with a string litterial, that's a syntax error.

answered 2012-05-17T23:46:51.173

Your Answer