CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   function objects and virtual inheritance (https://www.cfd-online.com/Forums/openfoam-programming-development/86914-function-objects-virtual-inheritance.html)

MichiB April 6, 2011 05:17

function objects and virtual inheritance
 
Hello Friends!

I'm having a little programming problem here, so hopefully one of you C++ experts can help me out of it!

I have programmed multiple function objects, using three 3 levels of inheritance.
1st) BaseLevel 2nd) MethodsLevel 3) CustomizedMethods- and OutputLevel

In order to overcome the diamond problem, I introduced virtual inheritances (e.g. class B :: virtual public A).

This however causes the following compilation error message:

/graz/home/openfoam/OpenFOAM/OpenFOAM-1.5-dev/src/sampling/lnInclude/IOOutputFilter.C: In constructor ‘Foam::IOOutputFilter<OutputFilter>::IOOutputFilte r(const Foam::word&, const Foam::objectRegistry&, const Foam::fileName&, Foam::IOobject::readOption, bool) [with OutputFilter = Foam::TurboPressure]’:
/graz/home/openfoam/OpenFOAM/OpenFOAM-1.5-dev/src/sampling/lnInclude/OutputFilterFunctionObject.C:78: instantiated from ‘bool Foam::OutputFilterFunctionObject<OutputFilter>::st art() [with OutputFilter = Foam::TurboPressure]’
HierarchyLevel2/TurboPressure/TurboPressureFunctionObject.C:41: instantiated from here
/graz/home/openfoam/OpenFOAM/OpenFOAM-1.5-dev/src/sampling/lnInclude/IOOutputFilter.C:53: error: no matching function for call to ‘Foam::TurboBase::TurboBase()’
lnInclude/TurboBase.H:157: note: candidates are: Foam::TurboBase::TurboBase(const Foam::word&, const Foam::objectRegistry&, const Foam::dictionary&, bool)
lnInclude/TurboBase.H:113: note: Foam::TurboBase::TurboBase(const Foam::TurboBase&)
make: *** [Make/linux64GccDPOpt/TurboPressureFunctionObject.o] Error 1


Apparently I'm calling the constructor Foam::TurboBase::TurboBase() on line 53 of file IOOutputFilter.C.
I don't know why the line's actual constructor Foam::TurboBase::TurboBase(const Foam::word&, const Foam::objectRegistry&, const Foam::dictionary&, bool) is not called, but it certainly has to do with the virtual inheritance declaration.

Any hints ????

vitor.geraldes@ist.utl.pt September 15, 2015 19:29

OpenFOAM is a great tool, but unfortunately we need sometimes to go inside the dark forest of multiple inheritance to get the job done! I tell this after seeing your old post and the following quotation
"...In object-oriented programming, Inheritance is the evil forest. Experienced programmers know to avoid this evil because they know that deep inside the Dark Forest Inheritance is the Evil Queen Multiple Inheritance. She likes to eat software and programmers with her massive complexity teeth, chewing on the flesh of the fallen. But the forest is so powerful and so tempting that nearly every programmer has to go into it, and try to make it out alive with the Evil Queen's head before they can call themselves real programmers. You just can't resist the Inheritance Forest's pull, so you go in. After the adventure you learn to just stay out of that stupid forest and bring an army if you are ever forced to go in again."(http://learnpythonthehardway.org/book/ex44.html)


All times are GMT -4. The time now is 18:20.