multiple inheritance, name collision in base classes

J

JenC

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
 
J

James Kanze

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() ;
} ;
 

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,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top