If I have a pure virtual base class with several derivations of it...
class Base
{
public:
virtual void method1() = 0;
}
class Derived1 : public Base
{
public:
void method1() override { ... }
}
class Derived2 : public Base
{
public:
void method1() override { ... }
}
Is there any way for code that holds a Base*
of an object of unknown derived type to determine the address of the method1()
function for the object it holds the Base*
pointer to?
What I want to do is something like this:
void someOtherFunction(Base * pb)
{
printf("If I call pb->method1(), it will call a function at %p.\n",
&(pb->method1));
}
But I get a compiler error:
error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function.
Ideally any solution would avoid RTTI & dynamic_cast
because that isn't enabled/allowed for my embedded system.