c++ - VS 说 "Too few arguments...",但其他编译器给我正确的输出?

标签 c++ recursion edit-distance

我正在编辑两个字符串之间的距离。它使用递归函数。在线编译器正在编译代码并给我输出 3,这是正确的,但是 visual studio 说“函数调用中的参数太少”其他人可以帮忙吗?

我看过其他线程,它们确实缺少参数,但我没有,但 VS 正在标记我的递归调用

#include<iostream> 
#include<string>
using namespace std;


int min(int x, int y, int z)
{
return min(min(x, y), z); // here VS flags error
}

int editDist(string str1, string str2, int m, int n)
{

if (m == 0) return n;


if (n == 0) return m;

if (str1[m - 1] == str2[n - 1])
    return editDist(str1, str2, m - 1, n - 1);

return 1 + min(editDist(str1, str2, m, n - 1),    
    editDist(str1, str2, m - 1, n),   
    editDist(str1, str2, m - 1, n - 1)
);
}


int main()
{
string str1 = "sunday";
string str2 = "saturday";

cout << editDist(str1, str2, str1.length(), str2.length());

return 0;
 }

最佳答案

问题是由于您的函数名称与标准最小函数 std::min 匹配所致

int min(int x, int y, int z){
    return min(min(x, y), z); // the compiler is getting confused over whether to 
    //call std::min which takes two parameters or user-defined min which 
    //takes three parameters
    }

更改您的函数名称,它应该可以正常工作。

关于c++ - VS 说 "Too few arguments...",但其他编译器给我正确的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55667792/

相关文章:

java - 如何使用递归构建嵌套链表?

typescript - Vue typescript 递归组件

对编辑距离感到困惑

edit-distance - 使用交换编辑距离

algorithm - 是否有考虑 "chunk transposition"的编辑距离算法?

C++ 对本地临时对象的引用

C++ std::map 与动态数组

java - 在功能上添加整数列表

c++ - pthreads 中的条件变量和释放多个锁

c++ - 使用指针写入标准容器