0

I am getting "'_comp' cannot be used as a function" error in the stl_algobase.h header file. Here is my code and the part of the header file that is supposed to have the error. code:

#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;
}

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;
    }

The compiler says that the error is in the line

if (__comp(__b, __a))
Vishesh Chanana
  • 115
  • 3
  • 5
  • 11

1 Answers1

8

It may not be the problem but the header of your min function specifies it needs 3 parameters : 2 of type __Tp and one of type _Compare but in your program, you call it with 3 type __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 !

EDIT : If you want to find out the min of three numbers, consider this post, with ints and float it is not needed to specify a comp function. For a quick fix, replace the line I highlighted with this one :

std::min({a[i][j-1], a[i-1][j], a[i-1][j-1]});
Thibault D.
  • 1,567
  • 10
  • 23