#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;' –