Covariant return types

From: Martin Stettner (nospam_at_martin.dot.stettner.at.complement.dot.at)
Date: 01/30/05


Date: Sun, 30 Jan 2005 20:17:49 +0100

Hi,

I would like to use covariant return types in mutual dependent classes like:

class IB;
class IA {
   virtual IB* getIB() = 0;
};
class IB{
   virtual IA* getIA() = 0;
};

class B;
class A : public IA{
   B *getIB(); /// Here I get an error!
   // If I replace with IB * getIB(); everything works fine
};

class B : public IB {
   A* getIA();
};

I understand, that the compiler cannot know - at the time of the
declaration of A::getIB() - that B derives from IB. Is there a way to do
some sort of forward declaration with "inheritance information" in order
to get the example to work?

thanks in advance

Martin