gpt4 book ai didi

c++ - Visual C++ 错误 C3867 和 C2664

转载 作者:行者123 更新时间:2023-11-30 04:21:29 26 4
gpt4 key购买 nike

#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

如果我尝试上面错误信息中的建议

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() 函数编译?这些 typedef 来 self 需要与之交互的库。

最佳答案

func是一个非静态成员函数,所以它的类型是bool (Class::*)(UCHAR, UCHAR),而Assign code> 需要 bool (*)(UCHAR, UCHAR)。您不能将非静态成员函数转换为非成员函数。

为了能够将 func 传递给 Assign,您必须将 func 设为静态。

关于c++ - Visual C++ 错误 C3867 和 C2664,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14501474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com