Lifetime issue with const member field
Opened this issue · 0 comments
pfultz2 commented
#include <iostream>
#include <string>
struct MyException
{
const std::string& msg;
MyException(const std::string& s) : msg(s)
{
}
};
int main(int argc, char** argv)
{
for (int i = 0; i < argc; ++i)
{
try
{
throw MyException(argv[i]);
}
catch (const MyException& e)
{
std::cerr << e.msg << std::endl;
}
}
}