考虑以下代码:
我得到的输出是:
#include <iostream>
#include <stdexcept>
class E{
public:
E(int n):m_n(n)
{
if (0>n)
{
throw std::logic_error("5");
}
}
~E(){cout << m_n << "#" <<endl;}
public :
int m_n;
};
int main()
{
try{
E a(5);
try{
E c(7);
E b(-8);
E d(9);
}
catch(const std::exception &e)
{
cout <<2 <<"&&&"<<e.what()<<endl;
throw e;
}
}
catch(const std::exception &e)
{
cout <<3 << "^^^^^ "<<e.what() << endl;
throw e;
}
return 0;
}
我得到的输出是:
7#
2&&&5
5#
3^^^^^ St9exception
std::exception: St9exception
Aborted.
请问为什么会得到这样的输出?我希望看到前五个#符号。
5#
,那就更好了,但这与是否过于局部化无关)。 - sepp2kif (i=0)
最多只会产生一个警告,但是if (0=i)
则会导致编译错误。 - Frerich Raabe