I want to implement a derived class that also needs to implement an interface that has a function that the base class can call. The following gives a warning, since it is unsafe to pass this pointer to the constructor of the base class:
struct IInterface
{
void FuncToCall() = 0;
};
struct Base
{
Base(IInterface* inter) { m_inter = inter; }
void SomeFunc() { inter->FuncToCall(); }
IInterface* m_inter;
};
struct Derived : Base, IInterface
{
Derived() : Base(this) {}
FuncToCall() {}
};
What is the best way to do this? I need to provide an interface as an argument to the base constructor, since this is not always a dumb class, which is an interface; sometimes it can be a completely different class.
I could add a function to the base class SetInterface (IInterface * inter), but I would like to avoid this.
source
share