3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

クラス内から関数ポインタ渡し

Posted at
Serial.h
void attach (void(*fptr)(void), IrqType type=RxIrq);

template<typename T>
void attach (T *tptr, void(T::*mptr)(void), IrqType type=RxIrq); 
controler.h
class Controler {
public:
    Controler(PinName pinTx, PinName pinRx);
   
private:    
    Serial _device;
};
controler.cpp

void Controler::attachRx()
{
    rxBuffer[rxVolume++] = _device.getc();
}

Controler::Controler(PinName pinTx, PinName pinRx) : _device(pinTx, pinRx) {
    Serial *p;
    p = &(_device);
    p->attach(this, &Controler::attachRx, Serial::RxIrq);
}

Controlerクラス内のvoid Controler::attachRx()を関数ポインタ渡しするため、
_device.attach(&attachRx, Serial::RxIrq);
と宣言しても通らなかったため、回避方法として。。。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?