65,189
社区成员




//
// function_pointer.h
//
#ifndef FUNCTION_POINTER_H
#define FUNCTION_POINTER_H
void f (char *, int *);
extern void ( *pf0 ) (char *, int *);
void (*fpf0( )) (char *, int *);
void (*fpf (void (*pf) (char *, int *))) (char *, int *);
#endif // FUNCTION_POINTER_H
//
// function_pointer.h
//
#ifndef FUNCTION_POINTER_H
#define FUNCTION_POINTER_H
void f (char *, int *);
extern void ( *pf0 ) (char *, int *);
void (*fpf0( )) (char *, int *);
void (*fpf (void (*pf) (char *, int *))) (char *, int *);
#endif // FUNCTION_POINTER_H
//
// function_pointer.cpp
//
#include <iostream>
using namespace std;
#include "function_pointer.h"
void
f(char *pc, int *pi)
{
cout << ">>>> " << __PRETTY_FUNCTION__ << endl;
cout << "==== " << "*pc=" << *pc << endl;
cout << "==== " << "*pi=" << *pi << endl;
cout << "<<<< " << __PRETTY_FUNCTION__ << endl;
}
void (*pf0)(char *, int *) = 0;
void
(*fpf0())(char *, int *)
{
cout << ">>>> " << __PRETTY_FUNCTION__ << endl;
cout << "<<<< " << __PRETTY_FUNCTION__ << endl;
return f;
}
void
(*fpf (void (*pf) (char *, int *))) (char *, int *)
{
cout << ">>>> " << __PRETTY_FUNCTION__ << endl;
cout << "<<<< " << __PRETTY_FUNCTION__ << endl;
return pf;
}
//
// main.cpp
//
#include <iostream>
using namespace std;
#include "function_pointer.h"
int
main()
{
int i;
char c;
i = 9;
c = 'A';
f(&c, &i);
pf0 = f;
pf0(&c, &i);
pf0 = fpf0();
pf0(&c, &i);
pf0 = fpf(fpf0());
pf0(&c, &i);
return 0;
}