1 声明一个函数类型
#include <cstdlib>
#include <iostream>
using namespace std;
void myprint(int a, int b)
{
cout << a << " " << b << endl;
}
typedef void (func)(int, int);
int main(int argc, char *argv[])
{
func* pFunc = myprint;
pFunc(1, 2);
system("PAUSE");
return EXIT_SUCCESS;
}
2 声明一个函数指针类型
#include <cstdlib>
#include <iostream>
using namespace std;
void myprint(int a, int b)
{
cout << a << " " << b << endl;
}
typedef void (*func2)(int, int);
int main(int argc, char *argv[])
{
func2 pFunc2 = myprint;
pFunc2(1, 2);
system("PAUSE");
return EXIT_SUCCESS;
}
3 定义一个函数指针变量
#include <cstdlib>
#include <iostream>
using namespace std;
void myprint(int a, int b)
{
cout << a << " " << b << endl;
}
int main(int argc, char *argv[])
{
void (*func3)(int, int) = myprint;
func3(1, 2);
system("PAUSE");
return EXIT_SUCCESS;
}