关于()操作符重载的问题
Question about () operator overloading
class Message
{
public:
std::string getHeader (const std::string& header_name) const;
// other methods...
};
class MessageSorter
{
public:
// take the field to sort by in the constructor
MessageSorter (const std::string& field) : _field( field ) {}
bool operator (const Message& lhs, const Message& rhs)
{
// get the field to sort by and make the comparison
return lhs.getHeader( _field ) < rhs.getHeader( _field );
}
private:
std::string _field;
};
std::vector<Messages> messages;
// read in messages
MessageSorter comparator;
sort( messages.begin(), messages.end(), comparator );
对于这一行:bool操作符(const Message&lhs, const Message&rhs)
对吗?应该是吗?bool operator() (const Message&lhs, const Message&rhs)
这段代码是Functor的教程示例代码。可以在这里看到:http://www.cprogramming.com/tutorial/functors-function-objects-in-c + + . html
谢谢
你明白了-可能是打错了,应该是
bool operator()(const Message& lhs, const Message& rhs)
相关文章:
- 一个关于在C++中重载布尔运算符的问题
- 在C++中使用重载提取运算符时出现问题
- 重载运算符与添加问题
- 加、乘、除、减复数的问题 C++ - 运算符重载
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- 关于重载 -> 运算符中 const 关键字的特定位置的问题
- 基于 SFINAE 的特征实现问题与函数模板重载
- 关于在成员重载中使用 std::move() 的问题
- 字符 * 未从重载运算符或内存管理问题正确返回
- constexpr 运算符重载使用参数的问题
- c++中重载输入运算符的问题
- 在C++中写入 4D 矢量时遇到问题(没有可行的重载"=")
- 我的重载函数有什么问题?
- C++使用模板参数来解决重载问题
- C++ 中重载成员函数的问题
- 我想知道我将如何实现 + 运算符重载.我已经从我上一个问题中计算出 += 运算符重载
- 为什么C++在自定义结构向量时会出现 ostream 重载问题?
- 解决 CRTP 函数重载歧义问题
- C++:创建线程时出现问题;错误 C2672:"std::invoke":找不到匹配的重载函数
- C++重载构造函数问题