r*******y 发帖数: 1081 | 1 bool compare(int i, int j){
cout <<"my compare "<< i << " "<< j << " " << (i < j)<
return i < j;
}
typedef bool(*comp)(int i, int j);
int main(){
setv(compare);
v.insert(1);
v.insert(0);
}
the out put is:
my compare 0 1 1
my compare 0 1 1
It seems the compare is called twice. I think it should be only
called once. So why twice here?
Thanks. | a*****i 发帖数: 268 | 2 I guess it checks 0<1 and 1<0. | r*******y 发帖数: 1081 | 3 from the output, it seems compare(0, 1) is called twice and
compare(1, 0) is not called.
【在 a*****i 的大作中提到】 : I guess it checks 0<1 and 1<0.
| f******y 发帖数: 2971 | 4 What compiler? Can you try insert more numbers, and see how many times the
compare is called? | r*******y 发帖数: 1081 | 5 g++
【在 f******y 的大作中提到】 : What compiler? Can you try insert more numbers, and see how many times the : compare is called?
|
|