设为首页 加入收藏

TOP

C++函数指针简单使用
2015-07-24 05:54:45 来源: 作者: 【 】 浏览:4
Tags:函数 指针 简单 使用

函数指针:

函数指针必须包含要调用的函数的内存地址,为了工作正确,指针还必须包含其他信息,即指针所指向的函数的参数列表中的参数类型以及返回类型。因此,在声明函数指针时,必须指定该指针可以指向的函数的参数类型和返回类型,以及指针名。

函数指针的一般形式如下:

返回类型(*指针明名)(参数类型列表);

注意:指针名上的括号是必不可少的,否则*就会与返回类型结合,就成了一个函数原型了。

示例:

#include 
  
   
using std::cout;
using std::endl;
//函数声明
long sum(long a,long b);
long product(long a,long b);
int main(int argc,char* argv[]){
	//函数指针声明
	long (*pfun)(long ,long)=0;
	//指向product函数
	pfun=product;
	cout<
    
      
    
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ -1573 Robot Motion 下一篇C++设计模式实现--职责链(Chain o..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: