【发布时间】:2019-10-04 09:01:44
【问题描述】:
我想在类构造函数中调用setCallback() 函数,并使用私有方法作为参数。由于函数所需的函数签名,这不起作用。我的函数问题是我无法访问我的类的特定对象的私有字段。
我已经尝试在类文件中创建一个由于静态上下文而无法工作的简单函数。我还尝试传递一个由于签名而不起作用的方法。
#include <PubSubClient.h>
class Test
{
private:
void callback(char *topic, uint8_t *payload, unsigned int)
{
// things
}
public:
Test(PubSubClient psc)
{
psc.setCallback(callback);
}
};
出现以下编译错误。
no suitable constructor exists to convert from "void (char *topic, uint8_t *payload, unsigned int)" to "std::function<void (char *, uint8_t *, unsigned int)>"
【问题讨论】: