I am kinda new to C , therefore, I don't know what is the cause of this error, I am trying to solve the edit distance problem recursively, however, this error shows up.
error: called object type 'int' is not a function or function pointer return __comp(__b, __a) ? __b : __a;
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int distance(string, string, int, int);
int cost(string, string, int, int);
int main(){
string v = "love";
string v2 = "hate";
cout<<distance(v, v2, v.size()-1, v2.size()-1);
}
int distance(string v, string v2, int a, int b)
{
if (a==0) return b;
if (b==0) return a;
return min(
distance(v, v2, a, b-1) 1,
distance(v, v2, a-1, b) 1,
distance(v, v2, a-1, b-1) cost(v, v2, a, b));
}
int cost(string v, string v1, int a, int b)
{
if (v[a]==v1[b]) return 0;
return 1;
}
CodePudding user response:
3rd argument of std::min
is the comparer, you might prefer the overload taking initializer_list:
return min({
distance(v, v2, a, b - 1) 1,
distance(v, v2, a - 1, b) 1,
distance(v, v2, a - 1, b - 1) cost(v, v2, a, b)});