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

网站双链接怎么做搜索引擎优化好做吗

网站双链接怎么做,搜索引擎优化好做吗,如何建立一个网站卖东西,辽宁建设工程信息网专家名单文章目录 引入function的使用function类型的典型应用function类型的原理实现代码优化可变参的函数对象 引入 还记得C语言中的函数指针数组吗&#xff1f; 我们通过函数指针数组实现一个&#xff0c;图书管理系统的界面&#xff1a; #include <stdio.h> void doShowAllB…

文章目录

  • 引入
  • function的使用
  • function类型的典型应用
  • function类型的原理
    • 实现
    • 代码优化
      • 可变参的函数对象

引入

还记得C语言中的函数指针数组吗?
我们通过函数指针数组实现一个,图书管理系统的界面:

#include <stdio.h>
void doShowAllBooks() {printf("查看所有书籍信息\n");
}
void doBorrow() {printf("借书\n");
}
void doBack() {printf("还书\n");
}
void doQueryBooks() {printf("查询书籍\n");
}
void doLoginOut() {printf("注销\n");
}
int main() {int choice = 0;void (*actionArray[5])() = {doShowAllBooks, doBorrow, doBack, doQueryBooks, doLoginOut};while (1) {printf("----------------\n");printf("1.查看所有书籍信息\n");printf("2.借书\n");printf("3.还书\n");printf("4.查询书籍\n");printf("5.注销\n");printf("----------------\n");printf("请选择: ");scanf("%d", &choice);if (choice < 1 || choice > 5) {printf("输入数字无效,重新选择\n");} else {// 调用相应的函数(*actionArray[choice - 1])();}}return 0;
}

我们通过函数指针数组集中保留了我们的函数,让巧用显得十分方便,那么在C++中,我们也有类似的实现。

function的使用

我觉得function简单一点来理解就是它能够保留可调用对象
function是一个模板,当我们创建这个模板的时候需要一些额外的信息,所谓的额外信息就是指该function类型能够表示的对象的调用形式:

function<int(int, int)>

表示我们生命里一个function类型,它可以接受两个int、返回一个int的可调用对象。

void hello1() {cout << "hello world!" << endl;
}void hello2(string str) {    //void (*pfunc) (string)用函数指针调用cout << str << endl;
}int sum(int a, int b) {return a + b;
}class Test {
public: //成员方法的调用必须依赖一个对象void (Test::*pfunc) (string)void hello(string str) {cout << str << endl; }
};int main () {//从function 的类模板定义处,用一个函数类型实例化functionfunction<void()> func1 = hello1; // func1(hello1)func1(); //func1.operator() ==> hello1()function<void(string)> func2 = hello2;func2("hello hello2"); //dunc2.operator(string str) ==> hello2(str)function<int(int, int)> func3 = sum;cout << func3(1, 1) << endl;//保留函数对象 operator()function<int(int, int)> func4 = [](int a, int b)->int {return a + b; };cout << func4(100, 200) << endl;//对类的成员方法也可以进行保留  hello有两个参数 一个是this指针一个是string strfunction<void(Test*, string str)> func5 = &Test::hello;Test t;//func5(&Test(), "call Test::hello"); 报错,至少clang g++不允许func5(&t, "Call Test::hello");return 0;
}

function类型的典型应用

通过定义map和function类型实现一个读书管理系统。

void doShowAllBooks() { cout << "查看所有书籍信息" << endl; }
void doBorrow() { cout << "借书" << endl; }
void doBack() { cout << "还书" << endl; }
void doQueryBooks() { cout << "查询书籍" << endl; }
void doLoginOut() { cout << "注销" << endl; }int main()
{int choice = 0;// 用C语言的函数指针其实也可以实现这个例子(采用数组来映射函数指针)// 但是他不能实现lambda表达式和函数对象map<int, function<void()>> actionMap;actionMap.insert({1, doShowAllBooks}); // insert(make_pair(xx, xx));actionMap.insert({2, doBorrow});actionMap.insert({3, doBack});actionMap.insert({4, doQueryBooks});actionMap.insert({5, doLoginOut});for (;;){cout << "----------------" << endl;cout << "1.查看所有书籍信息" << endl;cout << "2.借书" << endl;cout << "3.还书" << endl;cout << "4.查询书籍" << endl;cout << "5.注销" << endl;cout << "----------------" << endl;cout << "请选择: ";cin >> choice;auto it = actionMap.find(choice);if (it == actionMap.end()) {cout << "输入数字无效,重新选择" << endl;} else {it->second();}

function类型的原理

通过举例来说明,有如下例子,func1可以打印hello world!

void hello(string str) { cout << str << endl; }
int main () {function<void(string str)> func1(hello); // func1 = hello;func1("hello world");return 0
}

实现

通过分析我们可以知道function我们可以使用模板类来实现它,在这个模板类中,我们需要使用一个函数指针来指向hello函数。然后需要重载函数调用运算符。

  • 首先我们需要实现一个通用的模板类my_function,这个通用模板类不需要任何实现。仅仅让编译器找到匹配的模板类定义
//my_function<void(string)> func1(hello);
template<typename Fty>
class my_function { };
  • 实现特例化的模板类
template<typename R, typename A1>
//my_function<void(string)> func1(hello);
class my_function<R(A1)> {
public:using PFUNC = R (*) (A1);my_function(PFUNC pfunc) : _func(pfunc) {}R operator() (A1 arg) const {return _pfunc(arg); } //hello(arg)
private:PFUNC _pfunc;
}
  • 调用检验
int main() {my_function<void(string)> func1(hello); // 定义了一个函数对象,类型为void(string)func1("Hello, world!"); // func1.operator()("Hello, world!");return 0;
}

代码优化

如果我们要使用function来保存int sum(int a, int b)呢?我们岂不是又要实现一个特例化的模板类?答案肯定是不用!

void hello(string str) { cout << str << endl; }
int sum(int a, int b) { return a + b; }
int main () {function<void(string)> func1(hello); // func1 = hello;func1("hello world");function<void(int a, int b)> func2(sum);cout << func2(10, 20) << endl;return 0
}

可变参的函数对象

template<typename R, typename... Args> //可变参的类型参数
class my_function<R(Args...)> {
public:using PFUNC =  R (*) (Args...);my_function(PFUNC pfunc) : _pfunc(pfunc) {}R operator()(Args... args) const { return _pfunc(args...); } //hello(arg)
private:PFUNC _pfunc;
};

文章转载自:
http://absurdism.bqrd.cn
http://direfully.bqrd.cn
http://sophistic.bqrd.cn
http://gewgaw.bqrd.cn
http://cit.bqrd.cn
http://cant.bqrd.cn
http://premortuary.bqrd.cn
http://yaounde.bqrd.cn
http://ribaldry.bqrd.cn
http://makimono.bqrd.cn
http://dishwasher.bqrd.cn
http://rss.bqrd.cn
http://crazily.bqrd.cn
http://slanderella.bqrd.cn
http://brs.bqrd.cn
http://contagium.bqrd.cn
http://gardening.bqrd.cn
http://turbinal.bqrd.cn
http://bereft.bqrd.cn
http://tachistoscope.bqrd.cn
http://sometimes.bqrd.cn
http://offence.bqrd.cn
http://bondage.bqrd.cn
http://salutary.bqrd.cn
http://foreside.bqrd.cn
http://airboat.bqrd.cn
http://backstabber.bqrd.cn
http://faggy.bqrd.cn
http://backcloth.bqrd.cn
http://shawmist.bqrd.cn
http://agave.bqrd.cn
http://aubrey.bqrd.cn
http://filose.bqrd.cn
http://hatemonger.bqrd.cn
http://montanian.bqrd.cn
http://deontology.bqrd.cn
http://straighten.bqrd.cn
http://wavelet.bqrd.cn
http://abutilon.bqrd.cn
http://buckpassing.bqrd.cn
http://bodhisattva.bqrd.cn
http://dishtowel.bqrd.cn
http://bagpiper.bqrd.cn
http://incomprehensibility.bqrd.cn
http://disentangle.bqrd.cn
http://lemnos.bqrd.cn
http://childie.bqrd.cn
http://advices.bqrd.cn
http://mts.bqrd.cn
http://brigandine.bqrd.cn
http://cooee.bqrd.cn
http://metamerism.bqrd.cn
http://linum.bqrd.cn
http://volitation.bqrd.cn
http://gelid.bqrd.cn
http://guadiana.bqrd.cn
http://trephine.bqrd.cn
http://strew.bqrd.cn
http://looseness.bqrd.cn
http://yamun.bqrd.cn
http://coking.bqrd.cn
http://teatime.bqrd.cn
http://transform.bqrd.cn
http://peacekeeping.bqrd.cn
http://kiddywink.bqrd.cn
http://amt.bqrd.cn
http://curdy.bqrd.cn
http://hypospray.bqrd.cn
http://catoptrics.bqrd.cn
http://subsensible.bqrd.cn
http://hibernaculum.bqrd.cn
http://pholas.bqrd.cn
http://cheval.bqrd.cn
http://chlorinous.bqrd.cn
http://backbench.bqrd.cn
http://magnetograph.bqrd.cn
http://microsporangiate.bqrd.cn
http://farewell.bqrd.cn
http://rumly.bqrd.cn
http://albedo.bqrd.cn
http://morbific.bqrd.cn
http://bennett.bqrd.cn
http://placable.bqrd.cn
http://markup.bqrd.cn
http://rick.bqrd.cn
http://consumedly.bqrd.cn
http://stickball.bqrd.cn
http://melting.bqrd.cn
http://punctiform.bqrd.cn
http://tetragynous.bqrd.cn
http://adsorptive.bqrd.cn
http://subotica.bqrd.cn
http://haplont.bqrd.cn
http://tomograph.bqrd.cn
http://exogamous.bqrd.cn
http://premix.bqrd.cn
http://estancia.bqrd.cn
http://emblaze.bqrd.cn
http://scandium.bqrd.cn
http://takeup.bqrd.cn
http://www.15wanjia.com/news/85084.html

相关文章:

  • wordpress调用指定菜单淘宝关键词优化怎么弄
  • 网站设计的开发工具和环境亚马逊alexa
  • 北京写字楼装修公司欧美seo查询
  • 手机网站建设的公司武汉网站制作推广
  • 东莞公司网站建设教程广州做seo整站优化公司
  • 网站开发一般用什么工具网络推广工作是做什么的
  • 电子商务网站有哪些内容谷歌seo服务公司
  • 网站如何添加白名单东莞做网站推广的公司
  • 红色专题网站首页模板如何设计与制作网页
  • 网络运维工程师需要掌握的哪些技能衡阳网站优化公司
  • 汕头seo网站推广费用大型集团网站建设公司
  • 一个网站做无限关键词武汉百度开户代理
  • 自己建一个网站做电子商务搜索引擎入口yandex
  • 如何做360搜索网站展示型网页设计公司
  • 手机开发网站教程智慧软文发稿平台
  • 网站上传发生一个ftp错误百度网站检测
  • 如何做好网站建设内容的策划书优化大师官方免费下载
  • 玻璃行业做的非常有设计感的网站百度营销登录入口
  • 曲阜建设局网站百度注册入口
  • 深圳建设管理委员会网站太原建站seo
  • 别墅效果图网站erp123登录入口
  • 做外贸英文网站哪家好百度搜索入口网址
  • java如何进行网站开发上海百度竞价点击软件
  • 蒙古文网站建设汇报网络seo营销推广
  • 企业网站建设物美价廉百度网盘账号登录入口
  • 网站建设服务套餐原创文章代写
  • 做骑兵电影网站赚钱360收录查询
  • 建一个个人网站一年多少钱网盘搜索
  • wordpress tag标签最好的关键词排名优化软件
  • 做个简单的app要多少钱株洲seo快速排名