14

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.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
crobar
  • 2,810
  • 4
  • 28
  • 46

1 Answers1

26

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.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • 1
    Thanks, this solved the problem (i.e. header should indeed have been #include doh!). I'm using malloc because the code already has lots of calls to 'free' and 'calloc' etc. Is this a big problem, or can I leave it as it is? This isn't my code, it's someone else's. – crobar Jul 04 '11 at 10:30
  • 2
    @crobar: well, it's not wrong, just out of place. If it's not broken, don't fix it. Especially not if it's not your own code. – rubenvb Jul 04 '11 at 11:22