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
> 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