【发布时间】:2014-01-07 08:04:29
【问题描述】:
我对 C++ 异常有疑问:
#include <iostream>
#include <string>
using namespace std;
void some_function()
{
string str("Hello,World!");
throw(str);
}
int main()
{
try
{
some_function();
}
catch (string& e)
{
cout << e << endl;
e = "Hello, the world!";
cout << e << endl;
}
return 0;
}
在我的电脑上调试:
- 在
some_functionstr地址:0x003CF820 - int
maine地址:0x003CF738
我有三个问题,
- catch 参数是
string&,为什么我们在 main() 中得到 diff addr ? -
str不是临时值吗?为什么我们可以使用临时值引用? -
e存储在内存中的什么位置?
有人可以帮我吗?谢谢。
【问题讨论】:
-
那个问题不是重复的,但是那里的top answer 也涵盖了这个问题。
标签: c++