Because of my device I can\'t use virtual functions. Suppose I have:
class Base
{
void doSomething() { }
};
class Derived : public Base
{
void doSom
You can make your own vtable, I suppose. I'd just be a struct containing your "virtual" function pointers as part of Base, and have code to set up the vtable.
This is kind of a gross solution -- it's the C++ compiler's job to handle this feature.
But here goes:
#include
class Base
{
protected:
struct vt {
void (*vDoSomething)(void);
} vt;
private:
void doSomethingImpl(void) { std::cout << "Base doSomething" << std::endl; }
public:
void doSomething(void) { (vt.vDoSomething)();}
Base() : vt() { vt.vDoSomething = (void(*)(void)) &Base::doSomethingImpl;}
};
class Derived : public Base
{
public:
void doSomething(void) { std::cout << "Derived doSomething" << std::endl; }
Derived() : Base() { vt.vDoSomething = (void(*)(void)) &Derived::doSomething;}
};