这些代码是如何工作的?(多集排序)
How does this code works ? ( multiset sorting )
struct compare{
bool operator() ( const string& a , const string& b ) const{
return a.size() < b.size ();
}
};
multiset<string , compare> stg;
我正在解决一个问题,我想根据字符串长度对multiset进行排序。我在网上搜索了一下,得到了这个结构。这对我很有效……但我想知道这是如何工作的…
我只是对这行代码感到困惑。直到这一点,我认为结构只能包含变量,而不是函数…是不是有点像类中的重载。
bool operator() ( const string& a , const string& b ) const{
c++中的结构可以包含代码,但这通常是一个坏主意,因为您无法获得与类相同级别的封装。
但是,C语言中的结构体只是结构体,不能包含代码。
来源:https://msdn.microsoft.com/en-us/library/4a1hcx0y.aspx
相关文章:
- 为什么指针在对二维数组进行排序时无法正常工作?
- 排序功能在C++中未按预期工作
- 解释一下这个排序算法是如何工作的?
- 快速排序函数在快速排序算法中如何工作?
- 解释标准库排序函数C++的比较谓词的工作原理?
- 排序函数如何在整数对的向量上工作?
- 合并排序实施无法正常工作
- 运算符重载在 CPP 中的排序中如何工作?
- 快速排序动态大量对象无法正常工作
- 当输入向量称为储备金时,STD ::排序无法正常工作
- 排序功能无法正常工作
- std::sort与不严格的弱排序比较器可以作为拓扑排序工作
- 实现快速排序,几乎可以工作但不能
- 排序向量<变体<...>>无法通过运算符正常工作<
- 排序函数的第三个参数如何工作
- 合并排序无法在N logN中工作
- 快速排序程序停止工作
- 气泡排序:为什么它不能正常工作?
- 这种珠子排序算法的 c++ 实现是如何工作的
- 在 C++ 中工作排序函数