2010-10-06 179 views
0

在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; 

没有添加这些行,没有问题。任何人都想冒险猜测为什么?我在这里摸不着头脑,无法继续编写没有包含文件的单元测试。

回答

3

通过预处理器运行它,看看你得到了什么。也许near就是定义了某个东西,或者有些问题。 (很难不带行号说)

(我相信/ E或/ EP是正确的开关,但你可以在一个单一的文件VS GUI选项嫌弃..)

+0

好点,让我编辑,让你可以知道错误发生的地方 – wheaties 2010-10-06 20:26:17

+0

+1这比我的答案更可能。 :) – casablanca 2010-10-06 20:28:35

+0

这是它,谢谢。我讨厌他们的@#$#$%宏,它们会覆盖标准库的limits :: max()或limits :: min()。 – wheaties 2010-10-06 20:29:01

0

的顺序包括有时会导致奇怪的事情发生,事实上,这些“已知错误”在过去曾发生过VC++。试着对附件进行洗牌,看看它是否有帮助。

2

near是在WinDef.h中定义的宏。当您包含ATL标头时,它们可能间接包含WinDef.h。因此错误。

如果您确实需要这些标题,请停止使用标识符near#undef它包含在所有标题之后。

相关问题