Multiple Inheritance

Hi!

Am am currently working on a Phd project where I use C++ and a Finite Elemenet open source project called oofem to conduct my research. I have a problem concerning multpile inheritance. I have, to begin with three classes:

1
2
3
class Material {....}
class FluidDynamicMaterial : public Material {....}
class RVEMaterial : public Material {....}

Now, I want to create a fourth class that inherits both from FluidDynamicMaterial and RVEMaterial classes. Like:

class RVEStokesFlow : public RVEMaterial, public FluidDynamicMaterial {....}
When compiling I get the following error:

error: ‘oofem::Material’ is an ambiguous base of ‘oofem::rvestokesflow’

I cannot make changes in the classes Material and FluidDynamicMaterial since they come with the package and are used on numerous other places. RVEMaterial and RVEStokesFlow can be changed though. Why does it not work? And how can I solve this problem?

Sincerily
/Carl
In both classes you inherit from Material... You could virtually inherit...

It works like this:

1
2
3
class Material {...}
class FluidDynamicMaterial : virtual public Material {...} 
class RVEMaterial : virtual public Material {...}


Hope that helps...
Last edited on
Thanks but I cannot change FluidDynamicmaterial..
could you show me at what line it is?? Do you have an array of Material pointers???
See "What is the dreaded Diamond?" -> http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.8

Can you inherit FluidDynamicMaterial in RVEMaterial instead of the base Material, then only inherit RVEMaterial in RVEStokesFlow. Perhaps call it RVEFluidMaterial if you have other types of RVE Materials as well.

So...
1
2
3
4
class Material {....}
class FluidDynamicMaterial : public Material {....}
class RVEFluidMaterial : public FluidDynamicMaterial {....}
class RVEStokesFlow : public RVEFluidMaterial {....}


That would get rid of the ambiguous base class.
Last edited on
Topic archived. No new replies allowed.