C++ class::method() as driver callback
Posted: Mon Jan 27, 2014 3:24 pm
I want to encapsulate for example the uart driver inside a protocol communication class :
What kind of cast is it correct ?
Something like this ? (not really tried)
Maybe encapsulation of drivers inside class wouldn't be the best design choice?
Thanks in advance.
Code: Select all
class protocol{
UARTDriver *uart_drv;
UARTConfig uart_cfg;
public :
protocol(....){
...
uart_cfg.rxEnd = ( ? cast ? ) protocol::method;
}
private :
method(){
...
}
}
What kind of cast is it correct ?
Something like this ? (not really tried)
Code: Select all
typedef void(cb*)(UARTDriver*);
uart_cfg.rxEnd = reinterpret_cast<cb>(&protocol::method);
Maybe encapsulation of drivers inside class wouldn't be the best design choice?
Thanks in advance.