当前位置: 首页 > wzjs >正文

网站开发技术总结报告网络营销常见的工具

网站开发技术总结报告,网络营销常见的工具,淮南市城乡建设局网站,求几个能用的地址20211.函数对象 1.1 概念 重载函数调用操作符的类,其对象被称为函数对象 函数对象使用重载的()时,行为类似函数调用,也成为仿函数 本质:函数对象(仿函数)是一个类,不是一…

1.函数对象

1.1 概念

重载函数调用操作符的类,其对象被称为函数对象

函数对象使用重载的()时,行为类似函数调用,也成为仿函数

本质:函数对象(仿函数)是一个类,不是一个函数

1.2 函数对象的使用

在使用时可以像普通函数一样调用,可以有参数和返回值

函数对象可以有自己的状态

函数对象可以作为参数传递

#include <iostream>
#include <vector>using namespace std;class Myadd{public:int operator()(int x,int y){return x+y;}
};void test1(){Myadd ma;cout<<ma(10,10)<<endl;
}//可以有自己的状态
class MyPrint{public: MyPrint(){count=0;}void operator()(string test){cout<<test<<endl;count++;}int count;
};void test2(){MyPrint mp;mp("hello world");mp("hello world");mp("hello world");cout<<"调用了"<<mp.count<<"次"<<endl;
}// 可以作为参数传递
void DoPrint(MyPrint &mp,string test){mp(test);
}void test3(){MyPrint mp;DoPrint(mp,"hello world");
}int main()
{test1();test2();test3();system("pause");return 0;
}

 2.谓词

2.1 概念:

返回bool类型的仿函数称为谓词

如果operator()接收一个参数成为一元谓词

如果operator()接收两个参数成为二元谓词

2.2 一元谓词

一元谓词(Unary Predicate) 是一个接受一个参数并返回布尔值(true 或 false 的函数对象或函数。
其核心作用是:对单个输入值进行条件判断,返回是否满足特定条件。

#include <iostream>
#include <vector>
#include<algorithm>using namespace std;struct CreateFive{bool operator()(int x){return x>5;}
};void test(){vector<int> v;for(int i=0;i<10;i++){v.push_back(i);}vector<int>::iterator it = find_if(v.begin(),v.end(),CreateFive());// 查找满足CreateFive的元素,指向第一个满足条件的位置if (it==v.end()){cout<<"没有大于5的元素"<<endl;}else{cout<<*it<<endl;//只输出一个6}
}int main()
{test();system("pause");return 0;
}

2.3 二元谓词

二元谓词(Binary Predicate) 是一个接受两个参数并返回布尔值(true 或 false 的函数对象或函数。
其核心作用是:对两个输入值进行条件判断,返回是否满足特定关系。

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;class MyCompare{public:bool operator()(int v1,int v2){return v1>v2;}// 这个函数接受两个参数(v1 和 v2),返回一个布尔值(true 或 false),// 表示 v1 是否大于 v2。
};void test(){vector<int> v;v.push_back(10);v.push_back(20);v.push_back(30);v.push_back(40);v.push_back(50);sort(v.begin(),v.end());for(vector<int>::iterator it=v.begin();it!=v.end();it++){cout<<*it<<" ";   }cout<<endl;//改变排序顺序sort(v.begin(),v.end(),MyCompare());for(vector<int>::iterator it=v.begin();it!=v.end();it++){cout<<*it<<" ";   }cout<<endl;}int main()
{test();system("pause");return 0;
}

3.内建函数对象

3.1意义

STL内建了一些函数对象

需要在头文件#include<functional>

3.2算数仿函数

negate是一元运算,其他是二元运算,所以需要重载()

template<class T> T plus<T>;//加法

template<class T> T minus<T>;//减法

template<class T> T multiplies<T>;//乘法

template<class T> T divides<T>;//除法

template<class T> T modulus<T>;//取余

template<class T> T negate<T>;//取反

#include <iostream>
#include <functional>using namespace std;//negate
void Negate(){negate<int> n;cout<<n(10)<<endl;
}void Add(){plus<int> p;cout<<p(10,20)<<endl;
}int main()
{Negate();Add();system("pause");return 0;
}

3.3关系仿函数

实现关系对比

template<class T> bool equal_to<T>// 等号

template<class T> bool not_equal_to<T>// 不等号

template<class T> bool greater<T>// 大于

template<class T> bool less<T>// 小于

template<class T> bool greater_equal<T>// 大于等于

template<class T> bool less_equal<T>// 小于等于

#include <iostream>
#include <vector>
#include<functional>
#include<algorithm>using namespace std;class MyCompare{public:bool operator()(int x,int y){return x>y;}
};void test(){vector<int> v;v.push_back(10);v.push_back(80);v.push_back(30);v.push_back(50);v.push_back(70);for(vector<int>::iterator it=v.begin();it!=v.end();it++){cout<<*it<<" ";}cout<<endl;sort(v.begin(),v.end(),MyCompare());//STL内建仿函数sort(v.begin(),v.end(),greater<int>());for(vector<int>::iterator it=v.begin();it!=v.end();it++){cout<<*it<<" ";}cout<<endl;
}int main()
{test();system("pause");return 0;
}

3.4逻辑仿函数

template<class T> bool logical_and<T>// 逻辑与

template<class T> bool logical_or<T>// 逻辑或

template<class T> bool logical_not<T>// 逻辑非

#include <iostream>
#include <vector>
#include<functional>
#include<algorithm>using namespace std;void test(){vector<bool> v;v.push_back(true);v.push_back(false);v.push_back(true);v.push_back(false);for(auto it=v.begin();it!=v.end();it++){cout<<*it<<" ";}cout<<endl;vector<bool> v2;v2.resize(v.size());//将v2的大小设置为v的大小transform(v.begin(),v.end(),v2.begin(),logical_not<bool>());//遍历v,从v2的begin开始,将v的值取反,然后赋值给v2for(auto it=v2.begin();it!=v2.end();it++){cout<<*it<<" ";}cout<<endl;
}int main()
{test();system("pause");return 0;
}

http://www.dtcms.com/wzjs/290710.html

相关文章:

  • 免费空间已经注册 怎么做网站百度搜索词排名
  • 常州公司做网站seo优化排名推广
  • 深圳门户网站有哪些百度搜索热词排行榜
  • asp 网站 模板ui设计公司
  • 济南建站都选企汇优先做后付seo推广专员工作内容
  • 织梦怎么做中英文网站seo计费怎么刷关键词的
  • 杭州网站建设哪里好百度一下首页百度一下
  • 北京专业建网站的公司河北seo基础入门教程
  • 商铺装修找谁深圳百度快照优化
  • 网站建设上市公司淘宝数据分析
  • 重庆做网站建设公司p2p万能搜索引擎
  • 在线生成html廊坊seo排名外包
  • 临沂网站开发产品营销策划方案怎么做
  • 手机企业网站管理系统百度推广软件
  • 做外贸的怎么建立自己的网站百度一下搜索引擎大全
  • 三端网站如何做互联网营销师证书怎么考多少钱
  • 深圳商城网站建设做关键词优化的公司
  • 网站 硬件方案23岁老牌网站
  • 网站空间怎么买百度数据开放平台
  • iis做外网站点风云榜小说排行榜
  • 建设一个网站的方法如何快速推广一个新产品
  • 岳阳网站建设解决方案图片搜索
  • 2015做那个网站致富刷排名的软件是什么
  • 医院的网站建设目标百度seo服务
  • 怎么制作网站建设东莞做网站推广公司
  • 早教网站建设方案摘抄一则新闻
  • 旅游电子商务网站建设与研究个人如何建立免费网站
  • 如何在网站上做抽奖系统chrome下载
  • wordpress 主页插件网站优化包括对什么优化
  • 怎么搭建网页游戏私服高手优化网站