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

标签 c++ eclipse templates arguments min

我需要你的帮助

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/

相关文章:

java - 如何保存 Eclipse Natures 项目的自定义对象?

javascript - Angular .js : How to use ng-href in template?

C++ 我应该做什么而不是全局变量?

C++17 <functional> 模板参数推导不适用于 Xcode 10.1

c++ - 如何在 C++ 中使用 boost 创建线程池?

c++在子类和切片中重新定义类型

java - 是否可以在 Eclipse 中运行增量/自动 JUnit 测试?

eclipse - 如何以编程方式调整 eclipse ViewPart 的大小?

templates - 编程语言中的元函数和元类是什么意思?

c++ - std::conjunction 中的短路是如何工作的