将复杂的参数放入最低功能时会出现错误吗?为什么?(Eclipse C )
Getting error when putting complicated arguments in min function? Why?(Eclipse C++)
我需要你的帮助
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中遇到错误?
它说
描述资源路径位置类型 无效的论点 候选人是: const#0&min(const#0&,const#0&)
说明资源路径位置类型无匹配功能 到'min(__ __ GNU_CXX :: __ properte_2 :: __类型, int&)'tolledfulroad.h/corthfuload-c 线53 c/c 问题
以及其他一些信息,例如参数的冲突类型,模板参数扣除/替换失败。
错误消息意味着在此函数中调用
aSP[pos] = min( (dfs(i)+pow(i-pos,2)) , aSP[pos] );
第一个参数和第二个参数具有不同的类型。因此,编译器无法推论模板参数的类型。
您可以帮助编译器明确指定模板参数。例如
aSP[pos] = min<int>( (dfs(i)+pow(i-pos,2)) , aSP[pos] );
在函数的第二个呼叫中,两个参数都有type int。因此,将模板参数推导为int。
如果您有GCC错误,则更容易理解:
error: no matching function for call to 'min(double, int)'
std::min(2.0, 3);
^
只是将第一个参数施加到int。
相关文章:
- 我的字符计数代码计算错误.为什么
- C++ 错误 为什么这个矢量不输出?
- 当在函数调用中递增值时,程序正常工作,但是如果我们在单独的行中增加值而不是呼叫函数,则会出现错误.为什么
- 我正在将QPixmap传递给QAbstractButton::setIcon而不是QIcon,但我没有得到错误...为什么?
- 在 ZeroMQ 中绑定订阅者套接字并连接发布者套接字会在代码运行时给出错误.为什么
- 分段错误:为什么这里的数组索引越界了
- Box2D不寻常的错误.为什么 0阻止错误
- c++分段错误:为什么这个程序给出运行时错误(SIGSEGV)
- 链接列表错误 - 为什么头和尾引用指向相同地址
- VC++的一个大错误?为什么初始值设定项列表不对结构进行值初始化
- 分配大量内存会产生错误?为什么
- 得到一个段错误.为什么
- 变量名称与函数名称相同,导致编译器错误.为什么
- 访问在相应类的静态函数中创建的对象的私有成员变量不会导致错误.为什么?
- Qt5:此代码使用msvc2012编译正常,但使用MinGW编译时出现错误..为什么?
- 奇怪的错误-为什么编译器试图调用复制构造函数
- 我在使用 std::map 时收到此错误.为什么
- 我写了这个程序来反转链表中的元素,在编译这个程序后,在reverse()中显示错误.为什么
- Valgrind报告写入错误?为什么?
- 编译器错误 - 为什么我不能在Sublime Text 2中构建C++?