2010-10-06 143 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它包含在所有標題之後。

相關問題