C++ Multiple Inheritance: Implementing interfaces with overlapping virtual functions
I’m trying to design a class hierarchy in C++ where I have a base interface FooInterface
with a pure virtual function foo()
, and another interface FooBarInterface
that should extend FooInterface
and add an additional function bar()
. I then have a class Foo
that implements foo()
from FooInterface
, and a class FooBar
that inherits from Foo
and FooBarInterface
and implements bar()
.
My goal is to have the func
function accept a std::shared_ptr to any object that implements both foo()
and bar()
.
How to Implement a Function Accepting a Shared Pointer to an Object Implementing Multiple Interfaces in C++?
I’m trying to design a class hierarchy in C++ where I have a base interface FooInterface
with a pure virtual function foo()
, and another interface FooBarInterface
that should extend FooInterface
and add an additional function bar()
. I then have a class Foo
that implements foo()
from FooInterface
, and a class FooBar
that inherits from Foo
and FooBarInterface
and implements bar()
.
My goal is to have the func
function accept a std::shared_ptr to any object that implements both foo()
and bar()
.