gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:40:16 25 4
gpt4 key购买 nike

我正在编辑两个字符串之间的距离。它使用递归函数。在线编译器正在编译代码并给我输出 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com