当前位置:网站首页>sort函数使用cmp出错Line 22: Char 38: error: reference to non-static member function must be called
sort函数使用cmp出错Line 22: Char 38: error: reference to non-static member function must be called
2022-07-30 08:07:00 【pied_piperG】
出错代码
class Solution {
public:
int math(int n)
{
int ans = 0;
while (n)
{
n &= (n - 1);
ans++;
}
return ans;
}
bool cmp(int x, int y)
{
if (math(x) == math(y))
return x < y;
else
return math(x) < math(y);
}
vector<int> sortByBits(vector<int>& arr)
{
sort(arr.begin(), arr.end(), cmp);
return arr;
}
};
解决方法:将其它成员函数(cmp函数)移动到public外,或者加上static
class Solution {
public:
int math(int n)
{
int ans = 0;
while (n)
{
n &= (n - 1);
ans++;
}
return ans;
}
static bool cmp(int x, int y)
{
if (math(x) == math(y))
return x < y;
else
return math(x) < math(y);
}
vector<int> sortByBits(vector<int>& arr)
{
sort(arr.begin(), arr.end(), cmp);
return arr;
}
};边栏推荐
- SQL window function
- Field interpretation under "Surgical variables (RX SUMM-SURG OTH REG/DIS)" in SEER database
- ES报错处理-mapper [xx.xx] of different type, current_type [text], merged_type [keyword]
- The full arrangement of the 46th question in C language.Backtracking
- 集合相关Collection
- 电源完整性基础知识
- typescript1 - what is typescript
- DDR、GDDR、QDR的区别
- JS中对事件流的理解
- 立创EDA——PCB的走线(五)
猜你喜欢

基于SSM实现高校后勤报修系统

Windows 下安装 MySQL

一文读懂二十种开关电源拓扑结构

英语语法-名词性从句

电源完整性的去耦和层间耦合电容

一文带你玩转offer-01

PCB板加工流程中哪些因素会影响到传输线阻抗

Field interpretation under "Surgical variables (RX SUMM-SURG OTH REG/DIS)" in SEER database

jdbc ResultSetMetaData获取tableName问题

The blockbuster IP that has been popular in the world for 25 years, the new work has become a script paradise
随机推荐
hcip 第14天学习笔记
积分专题笔记-与路径无关条件
【SQL server速成之路】——身份验证及建立和管理用户账户
英语语法-名词性从句
Apache DolphinScheduler's new generation of distributed workflow task scheduling platform in practice - Part 1
瑞吉外卖项目(五) 菜品管理业务开发
反射技巧让你的性能提升 N 倍
桌面软件开发框架大赏
【科普向】5G核心网架构和关键技术
内卷下的智能投影行业,未来何去何从?
cmd命令
剑指offer 48:最长不重复子串
激活数据潜力 亚马逊云科技重塑云上存储“全家桶”
Judging from the Internet:
typescript5 - compile and install ts code
test2
C语言经典练习题(3)——“汉诺塔(Hanoi)“
342 · 山谷序列
[Unity]UI切换环形滚动效果
积分专题笔记-曲线面积分三大公式