Created
March 21, 2012 05:47
-
-
Save unixnut/2144903 to your computer and use it in GitHub Desktop.
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> | |
class boing | |
{ | |
public: | |
~boing() | |
{ | |
std::cout << "bye bye" << std::endl; | |
} | |
}; | |
void foo() | |
{ | |
throw boing(); | |
} | |
int main() | |
{ | |
try | |
{ | |
std::cout << "by value:" << std::endl; | |
foo(); | |
} | |
catch (boing e) | |
{} | |
try | |
{ | |
std::cout << "by reference:" << std::endl; | |
foo(); | |
} | |
catch (boing &e) | |
{} | |
return 0; | |
} |
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> | |
class boing | |
{ | |
public: | |
~boing() | |
{ | |
std::cout << "bye bye" << std::endl; | |
} | |
}; | |
void foo() | |
{ | |
throw boing(); | |
} | |
int main() | |
{ | |
try | |
{ | |
std::cout << "by value:" << std::endl; | |
foo(); | |
} | |
catch (boing e) | |
{ | |
std::cout << "caught it!" << std::endl; | |
} | |
try | |
{ | |
std::cout << "by reference:" << std::endl; | |
foo(); | |
} | |
catch (boing &e) | |
{ | |
std::cout << "caught it!" << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When this is compiled with GCC and run, it produced the following output: