类定义:CMemberFuncPointer

=======================================================================

 // MemberFuncPointer.h: interface for the CMemberFuncPointer class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX_MEMBERFUNCPOINTER_H__4D78718D_778E_4427_BBC1_C5F2D52C64E5__INCLUDED_)
#define AFX_MEMBERFUNCPOINTER_H__4D78718D_778E_4427_BBC1_C5F2D52C64E5__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 // 成员函数指针最大长度
#define MEMBER_FUNC_POINTER_MAX_SIZE 32
class CMemberFuncPointer
{
public:
void Reset();
void Set(const void*pFunc,int p_size);
void Get(void*pFunc);
CMemberFuncPointer();
CMemberFuncPointer(const char pointerdata[],int p_size);
CMemberFuncPointer(void* pointerdata,int p_size);
virtual ~CMemberFuncPointer(); bool operator==(const CMemberFuncPointer &mfp) const;
bool operator!=(const CMemberFuncPointer &mfp) const; CMemberFuncPointer& operator=(const CMemberFuncPointer &mfp); private:
int m_size;
char m_pointer_data[MEMBER_FUNC_POINTER_MAX_SIZE];
}; #endif // !defined(AFX_MEMBERFUNCPOINTER_H__4D78718D_778E_4427_BBC1_C5F2D52C64E5__INCLUDED_)

MemberFuncPointer.h

 // MemberFuncPointer.cpp: implementation of the CMemberFuncPointer class.
//
////////////////////////////////////////////////////////////////////// #include "stdafx.h"
#include "OverlapRoutine.h"
#include "MemberFuncPointer.h" #ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif //////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////// CMemberFuncPointer::CMemberFuncPointer()
{
this->m_size = ;
} CMemberFuncPointer::CMemberFuncPointer(const char pointerdata[],int p_size)
{
if(p_size<=MEMBER_FUNC_POINTER_MAX_SIZE)
{
this->m_size = p_size;
memcpy(this->m_pointer_data,pointerdata,p_size);
}
else
{
this->m_size = ;
}
} CMemberFuncPointer::CMemberFuncPointer(void* pointerdata,int p_size)
{
if(p_size<=MEMBER_FUNC_POINTER_MAX_SIZE)
{
this->m_size = p_size;
memcpy(this->m_pointer_data,pointerdata,p_size);
}
else
{
this->m_size = ;
}
} CMemberFuncPointer::~CMemberFuncPointer()
{ } bool CMemberFuncPointer::operator==(const CMemberFuncPointer &mfp) const
{
if(this->m_size==mfp.m_size) //mfp.m_size 可以访问私有成员
{
if(==memcmp(this->m_pointer_data,mfp.m_pointer_data,this->m_size))
{
return true;
}
} return false;
} bool CMemberFuncPointer::operator!=(const CMemberFuncPointer &mfp) const
{
if(this->m_size==mfp.m_size) //mfp.m_size 可以访问私有成员
{
if(==memcmp(this->m_pointer_data,mfp.m_pointer_data,this->m_size))
{
return false;
}
} return true;
} void CMemberFuncPointer::Get(void *pFunc)
{
memcpy(pFunc,this->m_pointer_data,this->m_size);
} void CMemberFuncPointer::Set(const void *pFunc,int p_size)
{
memcpy(this->m_pointer_data,pFunc,p_size);
this->m_size = p_size;
} void CMemberFuncPointer::Reset()
{
this->m_size = ;
} CMemberFuncPointer& CMemberFuncPointer::operator =(const CMemberFuncPointer &mfp)
{
if(this != &mfp)
{
memcpy(this->m_pointer_data,mfp.m_pointer_data,mfp.m_size); //mfp.m_pointer_data 可以访问私有成员
this->m_size = mfp.m_size; //mfp.m_size 可以访问私有成员
} return *this;
}

CMemberFuncPointer.cpp

05-11 22:04