error C2712: Cannot use __try in functions that require object unwinding
在解决问题后,我遇到了一阵子麻烦,剩下的代码非常简单,我不明白为什么会导致此错误。我在Windows下使用Visual Studio。
我正在使用/ EHa进行编译(我不使用/ EHsc)
我之所以__try/__except
不使用,try/catch
是因为我想捕获所有错误,并且不希望该程序在任何情况下都崩溃,例如除以0,try-catch不会捕获。
#include <string>
static struct myStruct
{
static std::string foo() {return "abc";}
};
int main ()
{
myStruct::foo();
__try
{ }
__except (true)
{ }
return 0;
}
输出:
error C2712: Cannot use __try in functions that require object unwinding
这是解决方案。有关更多详细信息,请阅读编译器错误C2712
#include <string>
struct myStruct
{
static std::string foo() {return "abc";}
};
void koo()
{
__try
{ }
__except (true)
{ }
}
int main ()
{
myStruct::foo();
koo();
return 0;
}
额外注意:static
如果不需要使用结构(myStruct)进行声明,则不需要。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句