C++ - 函子 vs 内联函数 vs 运算符重载
C++ - functor vs inline function vs operator overload?
基于各种堆栈溢出帖子,我将以下内容放在我不久前做的车牌识别程序中:
可能板.h:
(lines omitted)
std::string strChars;
///////////////////////////////////////////////////////////////////////////////////////////////
static bool sortDescendingByNumberOfChars(const PossiblePlate &ppLeft, const PossiblePlate &ppRight) {
return(ppLeft.strChars.length() > ppRight.strChars.length());
}
(lines omitted)
主.cpp
(lines omitted)
// sort the vector of possible plates in descending order (most number of chars to least number of chars)
std::sort(vectorOfPossiblePlates.begin(), vectorOfPossiblePlates.end(), PossiblePlate::sortDescendingByNumberOfChars);
(lines omitted)
如果更多上下文会有所帮助,这里是存储库:
https://github.com/MicrocontrollersAndMore/OpenCV_3_License_Plate_Recognition_Cpp
这段代码非常适合根据任何成员变量对C++中的对象向量进行排序,自从在其他各种项目中以来,我已经多次重复使用它。
我的问题是,这是什么? 函子、内联函数、运算符重载还是其他完全不同的东西? 如何确定差异?
也许我不明白这个问题,但如果这指的是 std::sort,我会说它是一个模板函数 ref
我的问题是,这是什么?函子、内联函数、运算符重载还是其他完全不同的东西?
它只是一个函数,被转换为指向函数的指针。函数指针可以在函数调用运算符中使用,因此它可以用作std::sort
的比较器。
相关文章:
- *&vs & 将变量传递给函数
- 为什么我的 GetProcessID 函数不在 VS 中编译?
- constexpr 函数的常量引用参数:gcc/msvc vs clang/icc
- VS 2017 C++编译器在 VS 2005 中找不到匹配函数
- 在VS 2017中,朋友通过具有私有析构函数的结构的unique_ptr向量进行迭代失败
- 模板函数仅适用于VS
- 重载函数 int vs double
- 使用函数参数作为常量表达式的一部分 - gcc vs clang
- 将参数传递给 c++ 构造函数时出现 VS 编译错误
- `noexcept`函数中的std :: terminate`调用函数有限-GCC vs clang codegen
- 性能:否则如果 vs if 在已经返回的函数中
- C++ std::stringstream 运算符<< vs (构造函数)
- VS为我提供了对构造函数的另一个解决方案,但我想知道为什么我的工作不起作用
- 睡眠() vs _sleep() 函数
- 函数指针的模板参数推导(g++ & ICC vs Clang++ & VC++)
- 类成员vs函数参数
- 并行OpenMP缩减vs.函数定义
- 静态constexpr变量vs函数
- 模板特化VS函数重载
- 指向函数形参的指针vs函数形参