I have a class Foo.
struct Foo
{
void someFunc()
{
}
};
I have an interface IFoo.
struct IFoo
{
virtual void someFunc() = 0;
};
If I didn't want to implement IFoo into Foo directly, is there a way to do it at a later point?
...
A FAILED attempt was to do this: Create a class which implements them both... THEORETICALLY satisfying IFoo by also inheriting from Foo.
struct Bar : Foo, IFoo
{
};
Which could be used like this:
Bar x = Bar();
IFoo* y = &x;
But that didn't work. The compiler sees Bar as abstract.
Does anyone have any ideas please? There is no actual code problem to paste, I am just trying to see if something like this would be possible.
struct Bar : IFoo, Foo
{
virtual void someFunc()
{
Foo::someFunc();
}
};
or:
struct Bar : IFoo
{
Foo foo;
virtual void someFunc()
{
foo.someFunc();
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With