In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.