64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
// 定义函数指针类型pFun
typedef int (*pFun)(const int&, const int&);
// 具体函数1
int intCompare(const int& aInt, const int& bInt)
{
if(aInt == bInt) return 0;
if(aInt > bInt)
{
return 1;
}
else
{
return -1;
}
}
// 具体函数2
int intSum(const int& aInt, const int& bInt)
{
return aInt + bInt;
}
int main(void)
{
int aInt = 1;
int bInt = 2;
// 用函数指针类型pFun声明并初始化一个函数指针pf
pFun pf = intCompare;
// 使用pf
if(pf(aInt, bInt) == 0)
{
cout << "two integers are equal" << "." << endl;
}
else if(pf(aInt, bInt) > 0)
{
cout << aInt << " is greater than " << bInt << "." << endl;
}
else
{
cout << aInt << " is less than " << bInt << "." << endl;
}
// 现在让函数指针pf指向intSum
pf = intSum;
cout << pf(aInt, bInt) << endl;
return 0;
}
//这段代码是什么意思?
#define schedule_selector(_SELECTOR) (SEL_SCHEDULE)(&_SELECTOR)
#define callfunc_selector(_SELECTOR) (SEL_CallFunc)(&_SELECTOR)
#define callfuncN_selector(_SELECTOR) (SEL_CallFuncN)(&_SELECTOR)
#define callfuncND_selector(_SELECTOR) (SEL_CallFuncND)(&_SELECTOR)
#define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR)
#define menu_selector(_SELECTOR) (SEL_MenuHandler)(&_SELECTOR)
#define event_selector(_SELECTOR) (SEL_EventHandler)(&_SELECTOR)