CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

OF-4.x: Multiple Inheritance of a functionObject

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 20, 2016, 10:08
Default OF-4.x: Multiple Inheritance of a functionObject
  #1
Member
 
Join Date: Jul 2011
Posts: 54
Rep Power: 14
A_Pete is on a distinguished road
Hey all,

I am trying to write a new functionObject and adjust it a little bit so that it fits the coding style of the new functionObjects library better.

Now, I am facing a problem since my functionObjectt is supposed to use both features of the writeFiles class and features of the fieldExpression class. These are both class where other functionObjects are derived from.

I don't want to make more than one functionObject out of it, since its usability is very limited and special for my cases. So I was thinking to derive from both writeFiles and fieldExpression classes. The beginnings of my class files look like this:

test.H:
Code:
namespace Foam
{
namespace functionObjects
{
class test
:
    public fieldExpression,
    public writeFiles
{ ...
test.C:
Code:
namespace Foam
{
namespace functionObjects
{
    defineTypeNameAndDebug(cavEroCDef, 0);
    addToRunTimeSelectionTable(functionObject, cavEroCDef, dictionary);
}
}
...
If I just derive from fieldExpression, my class works fine. If I add the writeFields class as a second base though, I get the following error:

Code:
In file included from /local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/token.H:49:0,
                 from /local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/runTimeSelectionTables.H:35,
                 from /local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/functionObject.H:115,
                 from /local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/regionFunctionObject.H:42,
                 from /local/OpenFOAM/OpenFOAM-4.x/src/finiteVolume/lnInclude/fvMeshFunctionObject.H:46,
                 from /local/OpenFOAM/OpenFOAM-4.x/src/functionObjects/field/lnInclude/fieldExpression.H:43,
                 from cavEroCDef/cavEroCDef.H:44,
                 from cavEroCDef/cavEroCDef.C:26:
/local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/functionObject.H: In instantiation of ‘static Foam::autoPtr<Foam::functionObject> Foam::functionObject::adddictionaryConstructorToTable<functionObjectType>::New(const Foam::word&, const Foam::Time&, const Foam::dictionary&) [with functionObjectType = Foam::functionObjects::cavEroCDef]’:
/local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/functionObject.H:164:9:   required from ‘Foam::functionObject::adddictionaryConstructorToTable<functionObjectType>::adddictionaryConstructorToTable(const Foam::word&) [with functionObjectType = Foam::functionObjects::cavEroCDef]’
cavEroCDef/cavEroCDef.C:43:5:   required from here
/local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/runTimeSelectionTables.H:72:64: error: ‘Foam::functionObject’ is an ambiguous base of ‘Foam::functionObjects::cavEroCDef’
             return autoPtr<baseType>(new baseType##Type parList);              \
                                                                ^
/local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/functionObject.H:164:9: note: in expansion of macro ‘declareRunTimeSelectionTable’
         declareRunTimeSelectionTable
         ^
/local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/functionObject.H: In static member function ‘static Foam::autoPtr<Foam::functionObject> Foam::functionObject::adddictionaryConstructorToTable<functionObjectType>::New(const Foam::word&, const Foam::Time&, const Foam::dictionary&) [with functionObjectType = Foam::functionObjects::cavEroCDef]’:
/local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/runTimeSelectionTables.H:73:9: warning: control reaches end of non-void function [-Wreturn-type]
         }                                                                      \
         ^
/local/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude/functionObject.H:164:9: note: in expansion of macro ‘declareRunTimeSelectionTable’
         declareRunTimeSelectionTable
         ^
/local/OpenFOAM/OpenFOAM-4.x/wmake/rules/General/transform:8: recipe for target '/local/OpenFOAM/OpenFOAM-4.x/platforms/linux64GccDPInt32Opt/src/functionObjects/cavErosion/cavEroCDef/cavEroCDef.o' failed
make: *** [/local/OpenFOAM/OpenFOAM-4.x/platforms/linux64GccDPInt32Opt/src/functionObjects/cavErosion/cavEroCDef/cavEroCDef.o] Error 1
The output says that the base is ambigous. I think that I have a diamond problem here. I can see that writeFiles and fieldExpression are derived from classes that can be directed back to the functionObject class. It seems like the problem occurs when registering in the runTimeSelectionTable of functionObject.

Does anybody have an idea how to solve this problem? It is really tempting for me to derive from both classes, since I use both their features.

Thanks in advance,
Andreas
A_Pete is offline   Reply With Quote

Old   September 21, 2016, 10:01
Default
  #2
Member
 
Join Date: Jul 2011
Posts: 54
Rep Power: 14
A_Pete is on a distinguished road
Consider this problem as solved, since I inherited from writeFields only and got basically all I wanted.
A_Pete is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set periodic boundary conditions Ganesh FLUENT 15 November 18, 2020 06:09
[OpenFOAM.org] Install openFOAM 3.0.1 in Ubuntu 16.04 LTS from Deb packs Pier84 OpenFOAM Installation 4 June 18, 2016 16:22
Create registered object at runtime using a functionObject CedricVH OpenFOAM Programming & Development 21 November 28, 2012 05:04
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 12:21
Multiple inheritance, function pointers or? ngj OpenFOAM 0 March 20, 2009 10:36


All times are GMT -4. The time now is 04:11.