#define UCHAR unsigned char
typedef bool (*FUNC)(UCHAR uc1, UCHAR uc2);
typedef void(*PF)(FUNC, UCHAR*);
PF Assign;
class Class {
private:
UCHAR buf[32];
bool func(UCHAR c1, UCHAR c2) { }
public:
Class::Class(void) {
Assign(func, buf); // <<< Microsoft VC++ error C3867
}
Class::~Class() { }
};
error C3867: 'Class::func': function call missing argument list; use '&Class::func' to create a pointer to member的Visual C++错误C3867和C2664
如果我尝试了上述
Assign(&Class::func, buf); // <<< Microsoft VC++ error C2664
错误消息的建议,我得到这个错误:
error C2664: 'void (FUNC,unsigned char *)' : cannot convert parameter 1 from 'bool (__thiscall Class::*)(unsigned char,unsigned char)' to 'FUNC' There is no context in which this conversion is possible
在不改变任何东西怎么能我得到这个Assign()函数来编译? 这些类型定义来自我需要接口的库。
永远不要这样做:'#定义UCHAR无符号char' - 始终使用一个typedef,例如'typedef unsigned char UCHAR;' –