#include <iostream>
#include <exception>
using namespace std;
class myexception: public exception
{
virtual const char* what() const throw()
{
return "My exception happened";
}
};
int main ()
{
try
{
myexception myex;
printf("addr1:%x\n",&myex);
throw myex;
}
catch (exception& e)
{
printf("addr2:%x\n",&e);
cout << e.what() << endl;
}
return 0;
}
该程序的输出:
addr1:6d78c020
addr2:20a1080
My exception happened
问题:你看到 addr1 和 addr2 不同吗,知道为什么吗?