Reputation: 35980
Compiling with Visual Studio 2005, on Windows XP. I add the following headers to my "stdafx.h" file like so:
#include <atlbase.h>
#include <atlcom.h>
#include <atlcore.h>
#include <atlstr.h>
(technically the same error appears with just atlbase.h included) which produces the following errors:
error C2334: unexpected token(s) preceding '{'; skipping apparent function body
error C2062: type 'double' unexpected
in the following code:
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;
Without those lines added, no problems. Anyone want to venture a guess as to why? I'm scratching my head here and can't continue writing unit tests without those include files.
Upvotes: 0
Views: 1406
Reputation: 320531
near
is a macro defined in WinDef.h
. When you include ATL headers, they probably indirectly include WinDef.h
. Hence the error.
If you really need those headers, either stop using identifier near
, or #undef
it right after all headers are included.
Upvotes: 2
Reputation: 70701
The order of includes can sometimes cause weird things to happen, and indeed, such "known bugs" have happened in the past with VC++. Try shuffling the includes around to see if it helps.
Upvotes: 0
Reputation: 25680
Run it through the preprocessor and see what you get. Maybe near is defined to something, or somesuch problem. (Hard to say without line numbers)
(I believe /E or /EP is the correct switches, but you can find it in the VS GUI options for a single file too..)
Upvotes: 3