Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NOMINMAX with Visual Studio 2012 MFC project [duplicate]

I want to use #define NOMINMAX in my Visual Studio C++ project using MFC, so that I can use std::min and std::max. However, when I put this line in my stdafx.h, I get following compile error:

c:\program files (x86)\windows kits\8.0\include\um\GdiplusTypes.h(475): error C3861: 'min': identifier not found

I am not using GDI+ intentionally, this is something MFC must be doing. Can the issue be fixed somehow, either by removing the GDI+, or by adjusting it to compile?

like image 428
Suma Avatar asked Apr 09 '13 11:04

Suma


1 Answers

I don't work on Windows so I'm not used to dealing with this, and I'm not testing this, but I believe that answer is suggesting you do this:

#define NOMINMAX
#include <algorithm>
namespace Gdiplus
{
  using std::min;
  using std::max;
};
//... your other includes.

This will get the "proper" versions of min and max, and make them available without the std:: prefix (which seems to be how it is used in the GdiplusTypes.h header).

like image 50
BoBTFish Avatar answered Oct 26 '22 23:10

BoBTFish