在Windows XP上使用Visual Studio 2005进行编译。我在我的"stdafx.h“文件中添加了以下头文件,如下所示:
#include <atlbase.h>
#include <atlcom.h>
#include <atlcore.h>
#include <atlstr.h>(从技术上讲,只包含atlbase.h就会出现相同的错误),这会产生以下错误:
error C2334: unexpected token(s) preceding '{'; skipping apparent function body
error C2062: type 'double' unexpected在以下代码中:
struct CheckValue : public unary_function<pair<MetID,double>,void>{
CheckValue(double _expected) : m_Expected(_expected){}
inline void operator()(const pair<MetID,double> &_val){
m_CheckList.push_back( near( _val.second ) ? 0 : 1 );
}
inline bool near(double _val){ //here is location of both errors
return ( m_Expected - m_Epsilon < _val ) || ( _val < m_Expected + m_Epsilon );
}
const static double m_Epsilon;
const double m_Expected;
list<int> m_CheckList;
};
const double CheckValue::m_Epsilon = 0.00001;如果不添加这些行,就没有问题。有没有人想冒险猜猜原因?我在这里摸不着头脑,没有那些包含文件就无法继续编写单元测试。
发布于 2010-10-07 04:24:51
通过预处理器运行它,看看会得到什么。也许near被定义为某事,或者某种类似的问题。(没有行号很难说)
(我相信/E或/EP是正确的开关,但您也可以在单个文件的VS选项中找到它。)
发布于 2010-10-07 04:39:47
near是在WinDef.h中定义的宏。当包含ATL标头时,它们可能间接包含WinDef.h。因此出现了错误。
如果你真的需要这些头文件,要么停止使用identifier near,要么在包含所有头文件后立即使用#undef。
发布于 2010-10-07 04:26:41
includes的顺序有时会导致奇怪的事情发生,事实上,这种“已知的bug”在过去的VC++中就曾发生过。尝试打乱包含的内容,看看是否有帮助。
https://stackoverflow.com/questions/3876544
复制相似问题