Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MinGW error: 'min' is not a member of 'std'

Tags:

c++

std

max

min

I'm trying to convert some VC++ 6 code to a console app using only the standard libraries but am getting the following error from MinGW (whatever version is supplied with the Code::Blocks 10.05 IDE):

error: 'min' is not a member of 'std'

This is related to the following line of code:

L.Precision=std::min(1.e-4,0.001*res);

L.Precision is a double, and res is a double. Previously this line was:

L.Precision=min(1.e-4,0.001*res);

But this gives the error:

error: 'min' was not declared in this scope

Here are the headers in the file in question:

#include<stdio.h>
#include<math.h>
//#include<algorithm.h>
#include <malloc.h>
#include "complex.h"
#include "mesh.h"
#include "spars.h"
#include "FemmeDocCore.h"

I understand that this may be related to some macros defined in the file windef.h, but correct me if I'm wrong about this.

What exactly can I do about this? I'm relatively new to C++, and am not even sure where windef.h is called for instance, I presume this is just needed for every windows program and is added at some point by MinGW. I want the final code to be cross-platform.

like image 248
crobar Avatar asked Jul 04 '11 10:07

crobar


1 Answers

You should uncomment and fix #include <algorithm>, (without the .h) which is where std::min is declared.

This has absolutely nothing to do with MinGW or GCC or Windows, this is standard C++ stuff. If you hit any other errors like this, search for the missing identifier on http://en.cppreference.com/w/.

Also: use <cmath> and <cstdio>, and avoid malloc and friends, use new/new[] and delete/delete[] instead.

like image 136
rubenvb Avatar answered Nov 16 '22 03:11

rubenvb