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

网站建设营销一站式服务/营销策略案例

网站建设营销一站式服务,营销策略案例,青岛高新区建设局网站,做网站百度新闻源c语言函数指针的定义形式:返回类型 (*函数指针名称)(参数类型,参数类型,参数类型,…); c函数指针的定义形式:返回类型 (类名称::*函数成员名称)(参数类型,参数类型,参数类型&#xf…

c语言函数指针的定义形式:返回类型 (*函数指针名称)(参数类型,参数类型,参数类型,…);

c++函数指针的定义形式返回类型 (类名称::*函数成员名称)(参数类型,参数类型,参数类型,….);    

以下代码编译环境:codeblocks with gcc in win 7

c语言函数指针使用举例: 

复制代码
#include <stdio.h>
#include <stdlib.h>int fun1()
{printf("this is fun1 call\n");return 1;
}void fun2(int k, char c)
{printf("this is fun2 call:%d %c\n", k, c);
}int main()
{int (*pfun1)() = NULL;void (*pfun2)(int, char) = NULL;int a,b;pfun1 = fun1; //第一种赋值方法a = pfun1();  //第一种调用方法(推荐)printf("%d\n",a);b = (*pfun1)();//第二种调用方法printf("%d\n",b);pfun2 = &fun2;//第二种赋值方法(推荐,因为和其他数据指针赋值方法一致)pfun2(1,'a');(*pfun2)(2,'b');return 0;
}
复制代码

 

c++函数指针使用举例:

复制代码
#include <iostream>
using namespace std;class test
{
public:test(){cout<<"constructor"<<endl;}int fun1(int a, char c){cout<<"this is fun1 call:"<<a<<" "<<c<<endl;return a;}void fun2(double d)const{cout<<"this is fun2 call:"<<d<<endl;}static double fun3(char buf[]){cout<<"this is fun3 call:"<<buf<<endl;return 3.14;}
};int main()
{// 类的静态成员函数指针和c的指针的用法相同double (*pstatic)(char buf[]) = NULL;//不需要加类名pstatic = test::fun3; //可以不加取地址符号pstatic("myclaa");pstatic = &test::fun3;(*pstatic)("xyz");//普通成员函数int (test::*pfun)(int, char) = NULL; //一定要加类名pfun = &test::fun1; //一定要加取地址符号
    test mytest;(mytest.*pfun)(1, 'a'); //调用是一定要加类的对象名和*符号//const 函数(基本普通成员函数相同)void (test::*pconst)(double)const = NULL; //一定要加constpconst = &test::fun2;test mytest2;(mytest2.*pconst)(3.33);//    //构造函数或者析构函数的指针,貌似不可以,不知道c++标准有没有规定不能有指向这两者的函数指针
//    (test::*pcon)() = NULL;
//    pcon = &test.test;
//    test mytest3;
//    (mytest3.*pcon)();return 0;
}
复制代码

 函数指针作为函数参数:

复制代码
#include <stdio.h>
#include <stdlib.h>void fun(int k, char c)
{printf("this is fun2 call:%d %c\n", k, c);
}void fun1(void (*pfun)(int, char), int a, char c)
{pfun(a, c);
}int main()
{fun1(fun, 1, 'a');return 0;
}
// c++ 的形式差不多
复制代码

函数指针作为函数返回值:

复制代码
// c 形式
#include <stdio.h>
#include <stdlib.h>void fun(int k, char c)
{printf("this is fun2 call:%d %c\n", k, c);
}//fun1 函数的参数为double,返回值为函数指针void(*)(int, char)
void (*fun1(double d))(int, char)
{printf("%f\n",d);return fun;
}int main()
{void (*p)(int, char) = fun1(3.33);p(1, 'a');return 0;
}
复制代码
复制代码
//c++ 形式
#include <iostream>
using namespace std;class test
{
public:int fun(int a, char c){cout<<"this is fun call:"<<a<<" "<<c<<endl;return a;}
};class test2
{public:// test2 的成员函数fun1,参数是double,//返回值是test的成员函数指针int(test::*)(int, char)int (test::*fun1(double d))(int, char){cout<<d<<endl;return &test::fun;}
};int main()
{test mytest;test2 mytest2;int (test::*p)(int, char) = mytest2.fun1(3.33);(mytest.*p)(1, 'a');return 0;
}
复制代码

函数指针数组:

复制代码
#include <stdio.h>
#include <stdlib.h>float add(float a,float b){return a+b;}
float minu(float a,float b){return a-b;}int main()
{//定义一个函数指针数组,大小为2//里面存放float (*)(float, float)类型的指针float (*pfunArry[2])(float, float) = {&add, &minu};double k = pfunArry[0](3.33,2.22);// 调用printf("%f\n", k);k = pfunArry[1](3.33,2.22);printf("%f\n", k);return 0;
}
//c++ 可类比
复制代码

typedef 简化函数指针类型:

复制代码
#include <stdio.h>
#include <stdlib.h>float add(float a,float b)
{printf("%f\n",a+b);return a+b;
}
float minu(float a,float b)
{printf("%f\n",a-b);return a-b;
}//用pfunType 来表示float(*)(float, float)
typedef float(*pfunType)(float, float);int main()
{pfunType p = &add;//定义函数指针变量p(3.33, 2.22);pfunType parry[2] = {&add, &minu};//定义函数指针数组parry[1](3.33, 2.22);//函数指针作为参数可以定义为:void fun(pfunType p)//函数指针作为返回值可以定义为:pfunType fun();return 0;
}
//c++ 可类比

转自:http://www.cnblogs.com/TenosDoIt/p/3164081.html
http://www.jmfq.cn/news/4739383.html

相关文章:

  • 松原手机网站开发公司/nba排名
  • 网站链接锚点怎么做/广西seo关键词怎么优化
  • 做网站都需要什么软件/友情链接怎么交换
  • 网址导航类网站怎么做/搜索引擎营销的分类
  • 想给公司注册一个网站/官网优化包括什么内容
  • 天津做艺术品的网站/免费网站推广软件
  • 做数据可视化图的网站/长沙seo优化哪家好
  • 长沙装修公司十大排名/seo软件推广
  • 专业的网站搭建多少钱/关键词查询网站
  • 做灯箱到哪个网站找业务/免费人脉推广软件
  • 做网站一定要有空间吗/网络媒体推广报价
  • 网站建设哪个公司靠谱/aso如何优化
  • 南京网站优化/排行榜网站
  • 无法解析您网站的域名./最近新闻小学生摘抄
  • 微信官网免费下载安装/成都高薪seo
  • 高校网站如何建设/百度客户端电脑版下载
  • 重庆网站建设公司推荐/seo企业优化顾问
  • 建网站前途/seo网站外链工具
  • 苏州晶体公司网站/个人免费开发网站
  • 去大连需要下载哪些软件/搜索引擎排名优化
  • 我的世界做圆网站/seo综合查询工具下载
  • 可以用AI做网站上的图吗/百度云app
  • 提供温州手机网站制作多少钱/北京互联网公司排名
  • 在线酒店预定网站制作/企业seo网站营销推广
  • 武汉武昌做网站推广/百度搜索技巧
  • 陇西 网站开发/全球最牛的搜索引擎
  • 如何建单页网站/黄页推广引流
  • 甘肃 政府网站信息内容建设/免费发广告的网站大全
  • 狮山做网站/百度电话客服
  • 怎么做国内外网站/网络推广员工资多少钱