Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C++ function object

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use C++ function object". In daily operation, I believe many people have doubts about how to use C++ function object. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about how to use C++ function objects. Next, please follow the editor to study!

Function object

Classes that overload function call operators are often called function objects (function object), that is, they are objects that behave like functions, also known as functor, which are actually overloaded "()" operators so that class objects can be called like functions.

Note:

1. A function object (imitating function) is a class, not a function.

two。 The function object (mock function) overloads the "()" operator so that it can be called like a function.

Classification: suppose a class has an overloaded operator (), and the overloaded operator () requires a parameter, we call the class a "unary unary functor" (unary functor); conversely, if the overloaded operator () requires two parameters, the class is called a "binary binary functor".

What is the main function of a function object? There are often two versions of the algorithms provided by STL, one of which shows the most commonly used operation, and the other allows users to specify the policy to be taken in the form of a template parameter.

/ / function objects are classes that overload function call symbols.

Class MyPrint

{

Public:

MyPrint ()

{

M_Num = 0

}

Int m_Num

Public:

Void operator () (int num)

{

Cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report