【发布时间】:2017-11-08 01:34:57
【问题描述】:
我在 stl_algobase.h 头文件中收到“'_comp' cannot be used as a function”错误。这是我的代码和应该有错误的头文件部分。 代码:
#include<iostream>
#include<algorithm>
using namespace std;
void subsqr(int a[10][10]){
//int s[][10];
for(int i =1;i<5;i++){
for(int j = 1;j<5;j++){
if(a[i][j] == 1){
a[i][j] = min(a[i][j-1], a[i-1][j],a[i-1][j-1]) + 1;
}
}
}
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
}
int main(){
int a[10][10] = {{0,1,1,0,1}, {1,1,0,1,0}, {1,1,1,0}, {1,1,1,1,0}, {1,1,1,1,1}, {0,0,0,0,0}};
subsqr(a);
return 0;
}
stl_algobase.h:
template<typename _Tp, typename _Compare>
inline const _Tp&
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
//return __comp(__b, __a) ? __b : __a;
if (__comp(__b, __a))
return __b;
return __a;
}
编译器说错误在行
if (__comp(__b, __a))
【问题讨论】:
-
不是双下划线前缀的名称可能被编译器保留吗?可能是冲突。
-
你认为你调用的是哪个
min()函数? -
请大家不要发布关于双下划线的无关 cmets。
-
很确定
__comp来自标准库。
标签: c++ multidimensional-array