64,654
社区成员
发帖
与我相关
我的任务
分享
struct MYCOUNT{
int* counter;
bool operator()(int a, int b){
(*counter)++;
return a <b;
}
};
int counter =0;
MYCOUNT mycount = {&counter};
这样无静态变量
struct {
bool operator()(int a, int b){
static int counter=0;
counter++;
std::cout << counter << std::endl;
return a < b;
}
}mycount;
这样也是可以的
bool mycount(int a, int b){
static int counter=0;
counter++;
std::cout << counter << std::endl;
return a < b;
}