gpt4 book ai didi

c++ - 将复杂参数放入 min 函数时出错?为什么?(Eclipse C++)

转载 作者:行者123 更新时间:2023-11-30 02:26:52 25 4
gpt4 key购买 nike

我需要你的帮助

if(s[i]==t)
{
//I get error for this
//aSP[pos] = min( (dfs(i)+pow(i-pos,2)) , aSP[pos] );

//Then I replace the above code with the following codes, and then it worked
int a = (dfs(i)+pow(i-pos,2));
int b = aSP[pos];
aSP[pos] = min(a,b);
}

但它们相同对吗?为什么我从 Eclipse 中收到错误消息?
它说

Description Resource Path Location Type Invalid arguments ' Candidates are: const #0 & min(const #0 &, const #0 &)

Description Resource Path Location Type no matching function for call to 'min(__gnu_cxx::__promote_2::__type, int&)' ColorfulRoad.h /colorfulroad-c++ line 53 C/C++ Problem

还有一些其他信息,例如参数类型冲突、模板参数推导/替换失败..

最佳答案

错误信息的意思是在这个函数调用中

aSP[pos] = min( (dfs(i)+pow(i-pos,2)) , aSP[pos] );

第一个和第二个参数有不同的类型。所以编译器无法推断模板参数的类型。

您可以帮助编译器显式指定模板参数。例如

aSP[pos] = min<int>( (dfs(i)+pow(i-pos,2)) , aSP[pos] );

在函数的第二次调用中,两个参数的类型都是 int。所以模板参数推导为int。

关于c++ - 将复杂参数放入 min 函数时出错?为什么?(Eclipse C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42327950/

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