Because of my device I can\'t use virtual functions. Suppose I have:
class Base
{
void doSomething() { }
};
class Derived : public Base
{
void doSom
I think it is possible with CRTP (if your 'Device' supports Templates).
#include
template struct base{
void g(){
if(T *p = static_cast(this)){
p->f();
}
}
void f(){volatile int v = 0; std::cout << 1;}
virtual ~base(){}
};
struct derived1 : base{
void f(){std::cout << 2;}
};
struct derived2 : base{
void f(){std::cout << 3;}
};
int main(){
derived1 d1;
d1.g();
derived2 d2;
d2.g();
}