c++函数指针

#include <iostream>
using namespace std;
//函数指针类型
void myfunc(int a,int b){
    cout<<a<<b<<endl;
}

void myfunc(char* a){
    cout<<*a<<endl;
}

//函数类型
//typedef void (mypfunc)(int a,int b);
//声明一个函数指针类型
typedef void (*mypfunc)(int a,int b);
//定义函数指针 指针变量可以直接使用
//void (*mypfunc)(int a,int b);

void main(){
    mypfunc p=NULL;
    p=myfunc;//把函数的入口地址复制给p
    p(1,2);//进行函数的调用
    char a[]="123";
    //p(a);报错,原因是定义的指针类型的为Int类型,不是char*
    cout<<"sxa"<<endl;
    system("pause");
}

 

posted @ 2015-11-07 18:26  爱读书de小学生  阅读(219)  评论(0编辑  收藏  举报