bool WindowContainer::GotoMainPage(bool bDestroyCurWndPage/* = true*/)
{
bool bResult = false;
LockChilds();
__try
{
GUIList::iterator it = m_lstWndPage.begin();// 这句话报错消息
if(it != m_lstWndPage.end() && (*it) != m_pCurPage)
{
WndPage * pCurPage = m_pCurPage;
SwitchToWndPage((WndPage *)*it, 0, 0);
bDestroyCurWndPage ? DestroyWndPage(pCurPage) : 0;
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
printf("\nWindowContainer::PopWndPage Catch Exception:%x!\n", GetExceptionCode());
}
UnLockChilds();
return bResult;
}
报错内容如下:
1>.\WindowContainer.cpp(576) : error C2712: 无法在要求对象展开的函数中使用 __try
解决方法:
错误消息
无法在要求对象展开的函数中使用 __try使用 /EHsc 时,带有结构化异常处理的函数不能具有要求展开(毁坏)的对象。
可能的解决方案:
-
将要求 SEH 的代码移动到另一个函数中。
-
重写使用 SEH 的函数以避免使用具有析构函数的局部变量和参数。在构造函数或析构函数中不要使用 SEH。
-
不使用 /EHsc 进行编译。
示例
如果使用 /clr:pure 进行编译并在 __try 块中声明指针到函数的静态数组,则会发生 C2712 错误。静态成员要求编译器在/clr:pure 下使用动态初始化功能,这意味着 C++ 异常处理。但是,不允许在__try 块中进行 C++ 异常处理。
下面的示例生成 C2712。
// C2712.cpp
// compile with: /clr:pure /c
struct S1 {
static int smf();
void fnc();
};
void S1::fnc() {
__try {
static int (*array_1[])() = {smf,}; // C2712
// OK
static int (*array_2[2])();
array_2[0] = smf;
}
__except(0) {}
}
参考CSDN:
http://msdn.microsoft.com/zh-cn/library/xwtb73ad(VS.80).aspx