'_comp'不能用作函数错误

Vis*_*ana -1 c++ multidimensional-array

我在stl_algobase.h标头文件中收到“'_comp'不能用作函数”错误。这是我的代码以及应该有错误的头文件部分。码:

#include<iostream>
#include<algorithm>

using namespace std;

void subsqr(int a[10][10]){
    //int s[][10];
    for(int i =1;i<5;i++){
        for(int j = 1;j<5;j++){
            if(a[i][j] == 1){
                a[i][j] = min(a[i][j-1], a[i-1][j],a[i-1][j-1]) + 1;
            }
        }
    }
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            cout<<a[i][j]<<"\t";
        }
        cout<<endl;
    }
}

int main(){
    int a[10][10] = {{0,1,1,0,1}, {1,1,0,1,0}, {1,1,1,0}, {1,1,1,1,0}, {1,1,1,1,1}, {0,0,0,0,0}};

    subsqr(a);  
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

stl_algobase.h:

 template<typename _Tp, typename _Compare>
    inline const _Tp&
    min(const _Tp& __a, const _Tp& __b, _Compare __comp)
    {
      //return __comp(__b, __a) ? __b : __a;
      if (__comp(__b, __a))
            return __b;
      return __a;
    }
Run Code Online (Sandbox Code Playgroud)

编译器说错误在一行

if (__comp(__b, __a))
Run Code Online (Sandbox Code Playgroud)

pLO*_*eGG 5

可能不是问题,但是min函数的标头指定它需要3个参数:2个类型为__Tp和一个类型为_Compare,但是在程序中,您可以使用3个类型__TP来调用它:

a[i][j] = min(a[i][j-1], a[i-1][j],a[i-1][j-1]) + 1; // the third parameter is an int, not a function !
Run Code Online (Sandbox Code Playgroud)

编辑:如果您想找出三个数字的最小值,请考虑使用int和float来发布此信息,无需指定comp函数。为了快速解决问题,请用以下内容替换我突出显示的行:

std::min({a[i][j-1], a[i-1][j], a[i-1][j-1]});
Run Code Online (Sandbox Code Playgroud)