Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

multiple inheritance, name collision in base classes

0 views
Skip to first unread message

JenC

unread,
Jan 28, 2009, 9:36:37 AM1/28/09
to
Hello,

I have a problem regarding multiple inheritance and name collision in
the base classes.
The problem looks like:

class BaseA
{
...
public:
virtual unsigned int Run();
...
}

class BaseB //note, BaseB is an abstract class
{
...
public:
virtual customType Run() = 0;
...
}

class Derived: public BaseA, public BaseB
{
...
public:
virtual customType Run(); //only need to implement/override
BaseB's Run()
}

The problem is that both base classes have a function Run(void)
differing only in their return types, and hence I get a compilation
error. Is there a way that I can specify that in class Derived I am
overriding BaseB's Run() method?

Changing the functions signature of BaseB::Run() is a last resort
option (BaseA cannot be changed), but it will affect a large amount of
code, so I would rather find a different less invasive solution. Any
ideas??


Thanks,
Jen Carlile

James Kanze

unread,
Jan 29, 2009, 3:25:48 AM1/29/09
to
On Jan 28, 3:36 pm, JenC <jcarl...@gmail.com> wrote:

> I have a problem regarding multiple inheritance and name
> collision in the base classes.
> The problem looks like:

> class BaseA
> {
> ...
> public:
> virtual unsigned int Run();
> ...
> }

> class BaseB //note, BaseB is an abstract class
> {
> ...
> public:
> virtual customType Run() = 0;
> ...
> }

> class Derived: public BaseA, public BaseB
> {
> ...
> public:
> virtual customType Run(); //only need to implement/override
> BaseB's Run()
> }

> The problem is that both base classes have a function
> Run(void) differing only in their return types, and hence I
> get a compilation error. Is there a way that I can specify
> that in class Derived I am overriding BaseB's Run() method?

Not directly.

> Changing the functions signature of BaseB::Run() is a last
> resort option (BaseA cannot be changed), but it will affect a
> large amount of code, so I would rather find a different less
> invasive solution. Any ideas??

The classical solution is to introduce an intermediate class
which "renames" the function:

class BaseB2 : public BaseB
{
public:
virtual customType Run()
{
return doRun() ;
}

virtual customType doRun() = 0 ;
} ;

class Derived : public BaseA, public BaseB2
{
public:
virtual customType doRun() ;
} ;

--
James Kanze (GABI Software) email:james...@gmail.com
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

0 new messages