码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 函数指针的定义方法及使用

时间:2015-08-25 14:12:39      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

 

int add(int a,int b){
    return a+b;
}

 

第一种,c语言通用。定义一个process_job函数指针类型,返回值为 int ,函数参数为int a,int b。使用用两种方法。

    typedef int (*process_job)(int a,int b);
    process_job a;
    a = add;

   cout << a(10,12) << endl;
    cout << (*a)(10,12) << endl; //OK

第二种,C++。使用,只有一种方法。

#include <functional>
typedef function< int(int,int)> task;
        task t = add;
    cout << t(22,23) << endl;     
       // cout << (*t)(22,23) << endl; error

 

C++ 函数指针的定义方法及使用

标签:

原文地址:http://www.cnblogs.com/cycxtz/p/4757075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!