Monday, April 16, 2007

valarray problem in Visual Studio

(Apr 16, 2007)

I tried to use valarray in Visual Studio and got some compile errors and warnings:
"warning C4003: not enough actual parameters for macro 'min'
warning C4003: not enough actual parameters for macro 'max'

error C2059: syntax error : ')'
c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\valarray(427) : see reference to class template instantiation 'std::valarray<_ty>' being compiled

error C2334: unexpected token(s) preceding ':'; skipping apparent function body

These problem will occur only when we try to use statically linked MFC library. In, Paul suggested that we need to make sure that valarray is included before afx stuff. This is because MS implements min and max macro and defines them in afx pre-compile header file. Any class that has min and max will have this problem.

However, if I switch the order, it seems that all declaration of valarray will be removed and I just got other compiler errors. It seems that the solution from Paul could not work for my situation.

After trying for a while, I finally decided to rename valarray.h to valarray_mod.h and change the function names from min and max to minimum and maximum instead.

No comments: