开发者

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

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 p开发者_开发问答oint by MinGW. I want the final code to be cross-platform.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜