增加Gdiplus相应的头文件Gdiplus.h后大概率会出现如下报错:
c:\program files (x86)\windows kits\8.1\include\um\GdiplusTypes.h(475): error C3861: “min”: 找不到标识符
c:\program files (x86)\windows kits\8.1\include\um\GdiplusTypes.h(477): error C3861: “max”: 找不到标识符
当前使用其他库也有一定概率会出现类似min、max报错,或者多重定义之类的,大家都喜欢用min和max函数名,windows甚至直接将min、max定义为宏,有点偏离了,继续说上面错误的解决方法
方法一:
#include <algorithm>
namespace Gdiplus
{
using std::min;
using std::max;
};
#include <Gdiplus.h>
#pragma comment( lib, "gdiplus.lib" )
方法二:
// 没定义min、max则定义
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define _MinDefTmp_
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define _MaxDefTmp_
#endif
#include <Gdiplus.h>
#pragma comment( lib, "gdiplus.lib" )
// 临时定义的则取消定义,避免其他地方错误
#ifdef _MinDefTmp_
#undef min
#undef _MinDefTmp_
#endif
#ifdef _MaxDefTmp_
#undef max
#undef _MaxDefTmp_
#endif
附带windows中minwindef.h的min、max宏定义
#ifndef NOMINMAX
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#endif /* NOMINMAX */
参考文章:
https://stackoverflow.com/questions/15900381/nominmax-with-visual-studio-2012-mfc-project