Re: Multiply inherit from classes with conflicting function names
Adam wrote:
I have an unfortunate case where a single class wants to
derive from two existing classes:
struct A { virtual long fun() = 0; };
struct B { virtual bool fun() = 0; };
struct Unfortunate : public A, public B { ??? };
Is it possible to fill in the ??? here with legal code?
Legal code, certainly. But nothing that would stop the class
from being abstract -- there's no way you can override fun().
I need two different function bodies; A::fun and B::fun do
unrelated things.
The classical solution is to create intermediate classes:
struct Abis { virtual long funA() = 0 ;
virtual long fun() { return funA() ; } } ;
struct Bbis { virtual bool funB() = 0 ;
virtual bool fun() { return funB() ; } } ;
struct Unfortunate : A, B
{
virtual long funA() { ... }
virtual long funB() { ... }
} ;
More or less the same question with a twist: if A::fun and
B::fun both returned the same type, would it be possible to
implement two functions in C such that
C().A::fun()
and
C().B::fun()
would execute two different functions?
Same solution as above.
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]