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

旧城冷巷雨未停 提交于 2019-11-30 02:51:15

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6570139/mingw-error-min-is-not-a-member-of-std

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!