Skip to content

Lifetime issue with const member field #21

Open

Description

@pfultz2
#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;
		}
	}
}

Activity

  1. changed the title [-]Lifetime issue with cons member field[/-] [+]Lifetime issue with const member field[/+] on Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions