In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how C++ uses imitation functions, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
The so-called imitation function is a call method very similar to function call. In fact, imitation function only overloads the () operator.
This approach is very common in STL container functions, which are divided into function objects and predicates
class t
{
public:
void operator ()(stu & a) function object (unary)
/*
bool operator ()(stu & a) predicate (unary), predicates only return boolean values
*/
};
void test (stu & a) function
So call it, and we can clearly see
imitated function call
t lfun;
lfun(a);
where lfun is the class object defined
Function calls are
test(a);
Their calls look remarkably similar.
The following demonstrates how to use the imitation function
Click here to fold or open
/** ***********************************************************************
> File Name: 201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> Author: gaopeng QQ:22389860 all right reserved
> Mail: gaopp_200217@163.com
> Created Time: Sun 23 Apr 2017 08:03:41 PM CST
************************************************************************/
#include
#include
#include
#include
using namespace std;
class testfun//imitation function
{
public:
testfun(void)
{
cnt = 0;
}
void operator()(int& a)
{
cnt++;
if( ! (a%67))
{
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.