我想将类成员函数地址存储到本地数据结构(表)
typedef struct
{
unsigned int id;
void (TCLASS::*proc)();
} TSTRUCT;
class TCLASS{
public:
void tfunct();
const TSTRUCT t1 = { 1, &tfunct};
};
答案 0 :(得分:0)
虽然你没有写一个问题,但假设你面临一堆编译错误。
见下文:
class TCLASS ; //forward declaration
struct TSTRUCT
{
unsigned int id;
void (TCLASS::*proc)( );
// // Use the TSTRUCT constructor
TSTRUCT(int i, void (TCLASS::*fptr)( ) ): id(i), proc(fptr)
{
}
} ;
class TCLASS{
public:
void tfunct();
TCLASS() : t1(1, &TCLASS::tfunct ) // initialize the const member
//~~~~~~~~~~~^ Use &TCLASS::tfunct instead of &tfunct
{
}
const TSTRUCT t1;
};