我最近更新到Visual Studio 2012,我遇到了一些异常规范问题。 我不断收到具有
形式的系统文件的错误<some type> function(<some input>) _NOEXCEPT
{
<some code>
}
其中
#define _NOEXCEPT throw()
我不太明白为什么我会得到错误,因为定义了宏并且使用是Visual Studio Exception Handling定义的。错误类似于:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\list(1119): error C2059: syntax error : '{'
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\list(1119): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
上面“list”文件的第1118-1121行是:
const_iterator begin() const _NOEXCEPT
{ // return iterator for beginning of nonmutable sequence
return (const_iterator(this->_Nextnode(this->_Myhead), this));
}
错误来自“list”和“xtree”,两者都位于上述路径中。 我已经尝试更改上面链接中指定的“\ EH”标志,但这没有帮助。
关于可能导致这种情况的任何想法?
编辑:添加预处理器文件摘录。
const_iterator begin() const {printf("ERROR: %s\n in file %s at line %d\n", ,"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\include\\list",1118); throw(1);}
{
return (const_iterator(this->_Nextnode(this->_Myhead), this));
}
不确定我应该从这个文件中做出什么,但这里是示例代码。
答案 0 :(得分:0)
修改强>
事实证明,有一个带宏的全局标题
#define throw(message) {printf("ERROR: %s\n in file %s at line %d\n", message,__FILE__,__LINE__); throw(1);}
导致所有问题。取消定义宏会使事情很好地解决。
我放弃了试图解决这个问题...... 作为解决方法,我重新定义了_NOEXCEPT宏以不使用throw,即
#define _NOEXCEPT
在导致问题的头文件中。
我不认为这会是一个主要问题,因为所有编译器都忽略了异常规范并在c ++ 11中弃用了