当我在MBED中使用InterruptIn类时,我开始收到此错误。我不知道该怎么解决。这是.fall函数的定义:
这是我的代码:
void Sensor::contador(int cont){
cont++;
}
int Sensor::medidaSensor(){
//Se activa el watchdog:
Timer timer;
timer.start();
int npulsos=0;
while(1){
//Cuenta los pulsos durante 5ms
if (timer.read_ms() < 5)
{
vcomp.fall(&contador(npulsos));
}
else{
//Kick the watchdog to reset its timer
watchdogTimer.kick();
}
}
return npulsos;
}
这是调用fall函数的正确方法(基于您附带的图片,我们不知道此函数的作用,但是没关系:
void Sensor::contador(int* cont){
++(*cont);
}
int Sensor::medidaSensor(){
//Se activa el watchdog:
Timer timer;
timer.start();
int npulsos=0;
while(1){
//Cuenta los pulsos durante 5ms
if (timer.read_ms() < 5)
{
vcomp.fall(&npulsos,contador);
}
else{
//Kick the watchdog to reset its timer
watchdogTimer.kick();
}
}
return npulsos;
}
根据您的fall
定义
我认为您想要:
vcomp.fall(this, &Sensor::contador);
即在当前对象上调用contador方法。
但是请注意,此方法不接受contador的参数,因此您不能调用当前的contador方法:您必须将count改为类中的一个字段,例如使用不同的fall()签名,例如接受回调函数的签名。 (恐怕我的C ++ lamdas生锈了,所以我不确定是否可以像其他语言一样使用带闭包的lambda复制此代码,否则是否会导致lambda的生存期出现问题。)] >