tags:

views:

39

answers:

3

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.

+3  A: 

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..)

Marcus Lindblom
Good point, let me edit so you can know where errors occur
wheaties
+1 this is more likely than my answer. :)
casablanca
This is it, thanks. I hate their @#$#$% macros which overwrite think like limits::max() or limits::min() of the standard library.
wheaties
@wheaties: NO_MINMAX is nice to define before including any windows-header. (or just do #undef min #undef max)
Marcus Lindblom
@Marcus: Note to self: NOMINMAX is the correct macro. :)
Marcus Lindblom
A: 

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.

casablanca
+2  A: 

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.

AndreyT