你能想到这样一种情况吗?如果你的程序没有到达你在main()开始时设置的断点,你的程序就会崩溃?
我的答案是在初始化静态变量时,但不确定...
发布于 2011-04-24 22:13:56
一个非常简单的例子
struct abc
{
abc()
{
int* p = 0;
*p = 42; // Drat!
}
};
abc obj;
int main(){}发布于 2011-04-24 22:25:49
THe上面的例子是真的,但根据我的经验,这通常是由于加载DLL时出现了一些问题……
发布于 2011-04-24 22:16:10
我的回答是100%保证这将在main()之前崩溃。
#include <exception>
struct A
{
A()
{
std::terminate(); //from <exception>
//you can also call std::abort() from <cstdlib>
}
};
A a;
int main(){}演示:http://www.ideone.com/JIhcz
另一种解决方案:
struct A
{
A()
{
throw "none";
}
};
A a;
int main(){}演示:http://www.ideone.com/daaMe
https://stackoverflow.com/questions/5770984
复制相似问题