据说是一个问题很多,但我找不到任何搜索高低的解决方案。我已经来了很多,改变了成员声明的方式,现在在构造函数中实例化Task对象,但还没有(当我大部分都知道我在做什么时,我不知道正确的术语很多话 - 对于这个游戏来说太新了。)
在实际的脚本中有多个这样的Task对象,它们都给出了基本相同的错误信息。
我正在尝试将一个类实例化为另一个类,问题是我必须传回一个函数。
标题文件:
#ifndef HYDROMONITORMASTER_H
#define HYDROMONITORMASTER_H
#include <TaskScheduler.h>
class HydroMonitorMaster
{
public:
HydroMonitorMaster (void);
private:
void readSensors(void);
Scheduler ts;
Task tReadSensors;
};
#endif
.cpp文件:
#include <HydroMonitorMaster.h>
HydroMonitorMaster::HydroMonitorMaster() : tReadSensors(10*1000, TASK_FOREVER, &HydroMonitorMaster::readSensors, &ts, false) {}
void HydroMonitorMaster::readSensors() {}
最后我得到的错误信息是:
Arduino: 1.8.1 (Linux), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 230400, 4M (3M SPIFFS)"
/home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp: In constructor 'HydroMonitorMaster::HydroMonitorMaster()':
/home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp:3:125: error: no matching function for call to 'Task::Task(int, int, void (HydroMonitorMaster::*)(), Scheduler*, bool)'
HydroMonitorMaster::HydroMonitorMaster() : tReadSensors(10*1000, TASK_FOREVER, &HydroMonitorMaster::readSensors, &ts, false) {}
^
/home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp:3:125: note: candidate is:
In file included from /home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.h:4:0,
from /home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp:1:
/home/wouter/Arduino/libraries/TaskScheduler-master/src/TaskScheduler.h:347:1: note: Task::Task(long unsigned int, long int, void (*)(), Scheduler*, bool, bool (*)(), void (*)())
Task::Task( unsigned long aInterval, long aIterations, void (*aCallback)(), Scheduler* aScheduler, bool aEnable, bool (*aOnEnable)(), void (*aOnDisable)() ) {
^
/home/wouter/Arduino/libraries/TaskScheduler-master/src/TaskScheduler.h:347:1: note: no known conversion for argument 3 from 'void (HydroMonitorMaster::*)()' to 'void (*)()'
exit status 1
真正的问题似乎是错误的结尾:no known conversion for argument 3 from 'void (HydroMonitorMaster::*)()' to 'void (*)()'
我不知道如何实现这一目标。