c++ derivatives problem

B

BosByte

Hello,

Please take a look at this well-known 'problem':

----------------
class A{
B * foo();
};

class B{
A * foo();
};
----------------

Its solution is simple: add "class B;" above A.


But here's a smilar, but more complex, problem:

----------------
class A_1 {
virtual B_1 * foo();
};

class B_1{
virtual A_1 * foo();
};


class A_2 : public A_1 {
virtual B_2 * foo(); //Overrides foo() of A_1. The return-type is
different, but it's okay because B_2 is a derivative of B_1
};

class B_2 : public B_1 {
virtual A_2 * foo(); //Overrides foo() of B_1. The return-type is
different, but it's okay because A_2 is a derivative of A_1
};
----------------

Adding "class B_1; class B_2;" on top of it doesn't solve the problem,
because the compiler only accepts the first override if it knows that
B_2 is a derivative of B_1.

How do I tell the compiler that B_2 is a derivative of B_1, without
having to specify all the contents of B_2 ?

Thanks in advance,
-Maurice-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top