做网站什么价格,微信推广平台怎么做,网站建设的基础常识,营销说白了就是干什么的当在类里面定义函数指针#xff0c;而函数指针会指向类里面的成员的时候#xff0c;这个时候成员需要定义为静态成员。实例代码如下#xff1a; //.h#define SCMD_REGISTER 0class CCallFuctionList{public:CCallFuctionList();virtual ~CCallFuctionList(void);typedef… 当在类里面定义函数指针而函数指针会指向类里面的成员的时候这个时候成员需要定义为静态成员。实例代码如下 //.h
#define SCMD_REGISTER 0
class CCallFuctionList
{
public:
CCallFuctionList();
virtual ~CCallFuctionList(void);
typedef void (* FUNCPTR)();
typedef std::multimapunsigned int, FUNCPTR FUNCMAP;
typedef std::multimapunsigned int, FUNCPTR::iterator FUNCMAP_ITERATOR;
static void CallDoRegister();
private:
static int i;
static FUNCMAP_ITERATOR m_funcIter;
FUNCMAP m_FuncMap;
};
//.cpp
int CCallFuctionList::i 0;
CCallFuctionList::FUNCMAP_ITERATOR CCallFuctionList::m_funcIter NULL;
CCallFuctionList::CCallFuctionList()
{
#define REGISTE_FUNC(type, func) m_FuncMap.insert(std::make_pair(type, func))
REGISTE_FUNC(SCMD_REGISTER, CallDoRegister);
REGISTE_FUNC(SCMD_REGISTER, CallDoRegister);
}
void CCallFuctionList::CallDoRegister()
{
i -1;
(m_funcIter-second)();
} 静态函数里面调用的所有类成员都需要设置为静态你肯定想不就全改成静态的就完了但静态变量都需要初始化且静态函数里面调用了静态的Vetor初始化起来比较麻烦还有种方式通过一种方式使函数指针调用c非静态函数。 代码如下 class CCallFuctionList
{
public:
CCallFuctionList();
virtual ~CCallFuctionList(void);
typedef void (CCallFuctionList::*FUNCPTR)();
typedef std::multimapunsigned int, FUNCPTR FUNCMAP;
typedef std::multimapunsigned int, FUNCPTR::iterator FUNCMAP_ITERATOR;
void CallDoRegister();
private:
FUNCMAP_ITERATOR m_funcIter;
FUNCMAP m_FuncMap;
int i;
};
CCallFuctionList::CCallFuctionList()
{
#define REGISTE_FUNC(type, func) m_FuncMap.insert(std::make_pair(type, func))
REGISTE_FUNC(SCMD_REGISTER, CCallFuctionList::CallDoRegister);
REGISTE_FUNC(SCMD_REGISTER, CCallFuctionList::CallDoRegister);
}
void CCallFuctionList::CallDoRegister()
{
i -1;
(this-*m_funcIter-second)();
}
传this指针进去是因为函数指针调用时默认并没将this传进去需要自己手动传