很简单的代码,并得到错误C2712,不明白为什么
very simple code, and getting error C2712, could not understand why
我有麻烦一段时间与error C2712: Cannot use __try in functions that require object unwinding
,缩小问题后,我留下了一个非常非常简单的代码,我不能理解为什么它会导致这个错误。我在windows下使用Visual Studio。
我正在编译/EHa(我不使用/EHsc)
我使用__try/__except
而不是try/catch
的原因是因为我想捕获所有错误,并且不希望程序在任何情况下崩溃,包括例如try-catch无法捕获的除0。
#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;
}
额外说明:如果没有使用struct (myStruct)的声明,则不需要static
。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 很简单的代码,并得到错误C2712,不明白为什么