1) Start VS2010 on Vista or Win7
2) Create new project: MFC Application
3) Click "Finish", i.e. use wizzard default settings.
4) Build Solution
5) Run target
> Application starts up and works as expected.
6) Insert the following lines at the beginning of stdafx.h
#define NOMINMAX
#define _INC_MINMAX
#include <xutility>
using std::min;
using std::max;
7) Build Solution
The following compiler errors occur:
Error 1 AllowTypeSafeMinMax error C2782: 'const _Ty &std::max(const _Ty &,const _Ty &)' : template parameter '_Ty' is ambiguous c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxtoolbar.h 171
Error 2 AllowTypeSafeMinMax error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 2 provided c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxtoolbar.h 171
Error 3 AllowTypeSafeMinMax error C2782: 'const _Ty &std::max(const _Ty &,const _Ty &)' : template parameter '_Ty' is ambiguous c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxmenubar.h 161
Error 4 AllowTypeSafeMinMax error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 2 provided c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxmenubar.h 161
Error 5 AllowTypeSafeMinMax error C2782: 'const _Ty &std::max(const _Ty &,const _Ty &)' : template parameter '_Ty' is ambiguous c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxdesktopalertwnd.h 81
Error 6 AllowTypeSafeMinMax error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 2 provided c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxdesktopalertwnd.h 81
See the attached sample project "AllowTypeSafeMinMax.zip"
Although these error messages are somewhat cryptic and C2780 is actually misleading, the remedy to fix this is simply an explicit type cast at the following code lines:
afxtoolbar.h(171)
afxmenubar.h(161)
afxdesktopalertwnd.h(81)
Please see the modified versions of these files in the folder "AllowTypeSafeMinMax\Fixed" of the sample project. Only the aforementioned headers are modified. The other headers have been included unmodified so that the project can be compiled without additional customizations.
You may also want to correct one line in the sample code of the C++/MFC Project Wizzard template files: OutputWnd.cpp(100)
The following compiler errors occur:
Error 1 AllowTypeSafeMinMax error C2782: 'const _Ty &std::max(const _Ty &,const _Ty &)' : template parameter '_Ty' is ambiguous c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxtoolbar.h 171
Error 2 AllowTypeSafeMinMax error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 2 provided c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxtoolbar.h 171
Error 3 AllowTypeSafeMinMax error C2782: 'const _Ty &std::max(const _Ty &,const _Ty &)' : template parameter '_Ty' is ambiguous c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxmenubar.h 161
Error 4 AllowTypeSafeMinMax error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 2 provided c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxmenubar.h 161
Error 5 AllowTypeSafeMinMax error C2782: 'const _Ty &std::max(const _Ty &,const _Ty &)' : template parameter '_Ty' is ambiguous c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxdesktopalertwnd.h 81
Error 6 AllowTypeSafeMinMax error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 2 provided c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\afxdesktopalertwnd.h 81