VS说"Too few arguments...",但其他编译器给了我正确的输出?
VS says "Too few arguments...", but other compilers give me a correct output?
我正在两个字符串之间进行编辑距离。它使用递归函数。在线编译器正在编译代码并给我一个 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
}
更改函数名称,它应该可以正常工作。
既然你用std::min
,就需要用#include <algorithm>
。
如果它适用于某些编译器,那是因为很幸运并且您使用的某些标头包含<algorithm>
(可能是间接的(。
相关文章:
- 与其他编译器相比,相同的代码在工作室Microsoft提供不同的输出
- 如何在程序执行时查看Valgrind Massif输出(或其他堆分析器)?
- 为什么在其他输出线之间得到"1"输出?
- bcdedit 文件输出不起作用,但其他命令可以
- Java 和其他语言在生成子序列时的输出差异
- VS说"Too few arguments...",但其他编译器给了我正确的输出?
- 字符串流不会输出其他变量吗?
- 为什么在浮点比较中,最后一个小数位数为5的浮点值能给出正确的输出,而在其他情况下却不是
- 如何将OpenCV的输出显示或流式传输到HTML页面或其他一些客户端应用程序
- 哪些数据文件从python(或其他)中读取的C 输出格式更有效
- 最后一行欧普特两个组合输出问题?如果其他语句
- C 链接列表仅输出其他每个元素
- 来自其他字符串的输出文件名
- 如何将opencv和其他dll文件链接到visual studio 2013的输出exe
- 将dll与c++项目中的其他输出文件分离
- 用于循环的C++没有以其他方式输出
- 如何在Qt中显示其他应用程序的输出视频
- GNU Radio没有来自与我自己的OOT块并行的其他块的输出
- Gradle C(本机)任务输出文件(用于其他任务/项目)
- 当键入指定单词作为第一个字母时显示输出,并忽略后面的其他单词