error C2780: “void std::sort(const _RanIt,const _RanIt)”: 应输入 2 个参数,却提供了 3 个

- 1.错误

warning C4018: “<”: 有符号/无符号不匹配
error C3867: “Solution::cmp”: 非标准语法;请使用 “&” 来创建指向成员的指针
error C2672: “std::sort”: 未找到匹配的重载函数
error C2780: “void std::sort(const _RanIt,const _RanIt)”: 应输入 2 个参数,却提供了 3 个
note: 参见“std::sort”的声明
1>已完成生成项目“Project1.vcxproj”的操作 - 失败。

VS2017运行出错:
在这里插入图片描述

2.修改方法

要想取类成员函数作为参数,该函数需要是static的,成员函数第一个参数默认是this指针, 加static 静态函数就没有this指针了。

public:
	static bool cmp(string& s1, string& s2)
	{
		return s1 + s2 < s2 + s1;
		//if( s1 + s2 < s2 + s1)return ;
	}

尝试把这个比较函数写在类的外面,重写了一个cm()的比较函数在可以编译通过

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于const std::shared_ptr的赋值,根据引用中的信息,在C++中,std::shared_ptr对象是可以被赋值给const std::shared_ptr的。具体来说,有以下几个赋值运算符可用于const std::shared_ptr对象赋值: - const std::shared_ptr<T>& operator=(const std::shared_ptr<T>& r) noexcept; (1):将一个std::shared_ptr对象的值赋给另一个const std::shared_ptr对象。 - template <class Y> const std::shared_ptr<T>& operator=(const std::shared_ptr<Y>& r) noexcept; (1):将一个std::shared_ptr<Y>对象的值赋给const std::shared_ptr<T>对象。 - const std::shared_ptr<T>& operator=(const std::shared_ptr<T>&& r) noexcept; (2):将一个右值std::shared_ptr对象的值赋给const std::shared_ptr对象。 - template <class Y> const std::shared_ptr<T>& operator=(const std::shared_ptr<Y>&& r) noexcept; (2):将一个右值std::shared_ptr<Y>对象的值赋给const std::shared_ptr<T>对象。 - template <class Y> const std::shared_ptr<T>& operator=(std::auto_ptr<Y>&& r); (3):将一个右值std::auto_ptr<Y>对象的值赋给const std::shared_ptr对象。(在C++11中已弃用,在C++17中已移除) - template <class Y, class Deleter> const std::shared_ptr<T>& operator=(std::unique_ptr<Y,Deleter>&& r); (4):将一个右值std::unique_ptr<Y,Deleter>对象的值赋给const std::shared_ptr对象。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [c++11 智能指针 (std::shared_ptr)(一)](https://blog.csdn.net/qq_40788199/article/details/126695619)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [c++11 智能指针 (std::shared_ptr)(二)](https://blog.csdn.net/qq_40788199/article/details/126695993)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值