【发布时间】:2016-05-24 13:21:29
【问题描述】:
此代码第 35 行的 abs() 函数出现错误。我选择的编译器:c++(4.3.2)
看看底部的错误。
void bfs(pair<int,int> pixelpos){
bfsq.push(pixelpos);
int u,v,i,j;
pair<int,int> tmpq;
while(!bfsq.empty()){
tmpq = bfsq.front();
u = tmpq.first; v = tmpq.second;
bfsq.pop();
r(i,u-square_dist,u+square_dist) r(j,v-square_dist,v+square_dist)
if(inrange(i,j)){
// ERROR HERE DOWN IN abs() fn
int dist = abs(pixelpos.first - i) + abs(pixelpos.second -j); // Line: 35
if(graph[i][j]>dist){
graph[i][j] = dist;
bfsq.push(pair<int,int> (i,j));
}
}
}
prog.cpp:在函数'void bfs(std::pair)'中:
prog.cpp:35: 错误:重载 'abs(int)' 的调用不明确
/usr/include/c++/4.3/cmath:99: 注意: 候选者是: double std::abs(double) /usr/include/c++/4.3/cmath:103: 注意:float std::abs(float)
/usr/include/c++/4.3/cmath:107: 注意:long double std::abs(long double)
prog.cpp:35: 错误:重载 'abs(int)' 的调用不明确
/usr/include/c++/4.3/cmath:99:注意:候选是:double std::abs(double)
/usr/include/c++/4.3/cmath:103: 注意:float std::abs(float)
/usr/include/c++/4.3/cmath:107: 注意:long double std::abs(long double)
可能是什么原因?
【问题讨论】:
-
"c++(4.3.2)" - 这不是编译器。你是说海合会吗?
-
@imvamshi 我认为原因是你没有包含标题
-
@ChristianHackl 是的。我忘了提。它的 GCC v4.3.2
标签: c++ overloading