函数对象
一、函数对象的本质函数对象(也称为仿函数,Functor)是*重载了函数调用运算符***operator()**的类或结构体的实例。这种特殊的设计使它能够像普通函数一样被调用,同时又具备对象的所有特性。 12345678910111213141516// 一个简单的函数对象类struct Add { // 重载函数调用运算符 int operator()(int a, int b) const { return a + b; }};// 使用方式int main() { Add add; int result = add(3, 5); // 像函数一样调用对象 // 也可以直接使用临时对象 int result2 = Add()(10, 20); return 0;} 从本质上讲,函数对象是一个带行为的对象,而普通函数是一段可执行代码。这种本质差异决定了它们在功能和适用场景上的不同。 二、函数对象与普通函数的核心区别2.1...


Recent Posts
Categories
- C++80
- C-Code23
- CMake3
- CS501
- Computer-Networking40
- Computer-Organization1
- Data Structures and Algorithms1
- Data-Structures6
- Essay1
- Essays4
- Foundational Syntax and Core Concepts3
- Git3
- HTTP2
- Interview7
- Lcov2
- Leetcode132
- Linux40
- Linux Internals2
- List1
- Lists1
- MQTT8
- MYSQL3
- MySQL1
- Operating-Systems7
- PKGCONF1
- Redis14
- STL3
- UML1
- XML1
- lock1
- practice problems1
- 代码提交1
- 函数模板2
- 工厂模式2
- 类图1
- 编译1
- 设计模式8
- 链表1
Archives
- 2026年01月 2
- 2025年12月 11
- 2025年11月 10
- 2025年10月 8
- 2025年09月 20
- 2025年08月 8
- 2025年07月 8
- 2025年06月 8
- 2025年05月 8
- 2025年04月 8
- 2025年03月 8
- 2025年02月 8
- 2025年01月 8
- 2024年12月 9
- 2024年11月 7
- 2024年10月 10
- 2024年09月 10
- 2024年08月 10
- 2024年07月 8
- 2024年06月 8
- 2024年05月 9
- 2024年04月 9
- 2024年03月 9
- 2024年02月 7
- 2024年01月 9
- 2023年12月 8
- 2023年11月 9
- 2023年10月 8
- 2023年09月 6
- 2023年08月 7
- 2023年07月 9
- 2023年06月 8
- 2023年05月 11
- 2023年04月 8
- 2023年03月 8
- 2023年02月 8
- 2023年01月 8
- 2022年12月 9
- 2022年11月 14
- 2022年10月 10
- 2022年09月 7
- 2022年08月 6
- 2022年07月 8
- 2022年06月 10
- 2022年05月 7
- 2022年04月 7
- 2022年03月 4
- 2022年02月 5
- 2022年01月 5
Website Info
Article Count :
410
Runtime :
Total Word Count :
684.8k
Last Update :