I have something like the attached. I basically have a Doer class in which I want to call Func() from it’s member without using virtual or with the least code duplication possible. Also, boost is not an option either. I know the example may not be so clear but I hope you get the idea. B
class Base { // a bunch of shared base functionality. Cannot be instantiated by itself }
class D1 : public Base
{
void Func();
}
class D2 : public Base
{
void Func();
}
//----
class Doer
{
Doer(Base* b) : base(b) { }
void DoIt()
{
base->Func();
}
Base* base;
}
Well, you can make
Doertemplated:But for this I would just add a
virtual void Func()toBaseinstead.Note that you’ll probably want to make
Funcpublic in either case 🙂