It’s ok,
having:
class A
{
virtual x() = 0;
virtual y() = 0;
}
class B
{
virtual x() = 0;
virtual z() = 0;
}
class C : A , B
{
x();
y();
z();
}
to share instances of class C with two libraries whose one knows only of A and another knows only of B?
Like:
Library 1:
#include <a>
A* a = function_in_the_core_that_creates_a_C_and_retrieves_it();
a->x();
a->y();
Library 1:
#include <b>
B* b = function_in_the_core_that_creates_a_C_and_retrieves_it();
b->x();
b->z();
I’m asking this because I wonder if the compiler will have problems to resolve the functions since the libraries don’t have a full knowledge of the ancestry of C.
EDIT:
function_in_the_core_that_creates_a_C_and_retrieves_it() is supposed to return a C* not a C. I thought that that was clear since we are talking about virtual functions.
You really should make the code compile. C is privately inheriting A and B, so this example isn’t going to run.
class C : public A , public Bis the corrected declaration forC. You are also missing return types for the functions.Either
function_in_the_core_that_creates_a_C_and_retrieves_itwill return aB*, which will then conform to the full ancestry ofBand work as aBfor all intents and purposes – or it will return aC*, in which case you will have to provide a full declaration ofCin order for the assignment to work without an explicit cast. You cannot haveCjust forward declared to do this.So, you’re either returning a pointer to
Bin which case there is no problem – or a pointer toCwhere you will need to provide full ancestry in order to make the assignment without a potentially dangerous cast.