Created
August 16, 2023 15:00
-
-
Save mmomtchev/0544f11b1ff104c7b5498e6aed8cbf9b to your computer and use it in GitHub Desktop.
Copying `std::exception` with an error message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() { | |
auto err = std::logic_error("some error"); | |
std::cout << err.what() << std::endl; | |
// using the derived copy constructor | |
std::logic_error err2 = err; | |
std::cout << err2.what() << std::endl; | |
// what() is virtual | |
std::exception &err3 = err; | |
std::cout << err3.what() << std::endl; | |
// This slices the object | |
std::exception err4 = err; | |
std::cout << err4.what() << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment