我的问题:
在写仿函数的时候我是这样写的:
//仿函数
class MyCompare
{
public:
bool operator()(int v1, int v2)//重载()
{
return v1 > v2;
}
};
报错:
已启动生成…
1>------ 已启动生成: 项目: STL, 配置: Debug Win32 ------
1>41set容器-排序.cpp
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xutility(1622,19): error C3848: 具有类型“const MyCompare”的表达式会丢失一些 const-volatile 限定符以调用“bool MyCompare::operator ()(int,int)”
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xutility(1621): message : 查看对正在编译的函数 模板 实例化“bool std::_Debug_lt_pred<const MyCompare&,const _Kty&,const _Keyty&,0>(_Pr,_Ty1,_Ty2) noexcept(<expr>)”的引用
1> with
1> [
1> _Kty=int,
1> _Keyty=int,
1> _Pr=const MyCompare &,
1> _Ty1=const int &,
1> _Ty2=const int &
1> ]
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xtree(1002): message : 查看对正在编译的函数 模板 实例化“std::_Tree_find_result<std::_Tree_node<int,std::_Default_allocator_traits<_Alloc>::void_pointer> *> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Find_lower_bound<_Key>(const _Keyty &) const”的引用
1> with
1> [
1> _Alloc=std::allocator<int>,
1> _Kty=int,
1> _Pr=MyCompare,
1> _Key=int,
1> _Keyty=int
1> ]
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xtree(1009): message : 查看对正在编译的函数 模板 实例化“std::_Tree_find_result<std::_Tree_node<int,std::_Default_allocator_traits<_Alloc>::void_pointer> *> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Find_lower_bound<_Key>(const _Keyty &) const”的引用
1> with
1> [
1> _Alloc=std::allocator<int>,
1> _Kty=int,
1> _Pr=MyCompare,
1> _Key=int,
1> _Keyty=int
1> ]
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xtree(1344): message : 查看对正在编译的函数 模板 实例化“std::pair<std::_Tree_node<int,std::_Default_allocator_traits<_Alloc>::void_pointer> *,bool> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Emplace<int>(int &&)”的引用
1> with
1> [
1> _Alloc=std::allocator<int>,
1> _Kty=int,
1> _Pr=MyCompare
1> ]
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xtree(1344): message : 查看对正在编译的函数 模板 实例化“std::pair<std::_Tree_node<int,std::_Default_allocator_traits<_Alloc>::void_pointer> *,bool> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Emplace<int>(int &&)”的引用
1> with
1> [
1> _Alloc=std::allocator<int>,
1> _Kty=int,
1> _Pr=MyCompare
1> ]
1>C:\Users\matebook\Desktop\C++练习\STL\41set容器-排序.cpp(35): message : 查看对正在编译的函数 模板 实例化“std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<int>>>,bool> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::insert<false,0>(int &&)”的引用
1> with
1> [
1> _Kty=int,
1> _Pr=MyCompare,
1> _Alloc=std::allocator<int>
1> ]
1>C:\Users\matebook\Desktop\C++练习\STL\41set容器-排序.cpp(35): message : 查看对正在编译的函数 模板 实例化“std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<int>>>,bool> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::insert<false,0>(int &&)”的引用
1> with
1> [
1> _Kty=int,
1> _Pr=MyCompare,
1> _Alloc=std::allocator<int>
1> ]
1>已完成生成项目“STL.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========