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

Lazy programming: ommitting multiple inheritance

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 18, 2021, 12:35
Default Lazy programming: ommitting multiple inheritance
  #1
Member
 
Bram Kerkhofs1
Join Date: Oct 2016
Posts: 30
Rep Power: 9
brammekeuh987 is on a distinguished road
Dear Foamers

Untill now I've been able to program my own function objects by copying useful code from different existing function objects. So far everything is working, but it's always a hustle of selecting the code and reading existing code, which takes a lot of time. So I figured that it would just be more easy to just make instances of the existing classes and 'grab' the info from the instances and preform the action you want to preform on them.

So the goal is for instance to make the header file like this:
Code:
#include "functionA.H"
#include "functionB.H"
#include "functionC.H"



// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


namespace Foam
{
namespace functionObjects
{



/*---------------------------------------------------------------------------*\
                   Class myOwnStuff Declaration
\*---------------------------------------------------------------------------*/

class myOwnStuff
:
    public functionA,
    public functionB,
    public functionC,
{

    // Private Data
.......
So when I tried to do this I inevitably stumbled upon issues with multiple inheritance: i.e. the same function or variable gets loaded a second time. For instance the variable 'mesh_'.
This variable is an fvMesh and is being used multiple times in different classes and represents (most of the time) the same thing. An fvMesh holds a lot of information which you want to extract. But since this is created multiple times your compiler returns a lot of errors. Not only instances of classes but also methods and variables are inherited multiple times. So this is more than just one type of diamond problem.

My question is: is there an elegant way of programming like this and ommitting the multiple inheritance issues?

For instance: the 'mesh_' errors can be omitted by declaring a private data member
Code:
        //- Reference to the fvMesh
        const fvMesh& mesh_;
and writing this in the constructor:
Code:
mesh_(refCast<const fvMesh>(obr_))
I wasn't able to compile everything so I don't know if this would really solve the problem
brammekeuh987 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 07:09
Multiple inheritance paradigms in OpenFOAM raumpolizei OpenFOAM Programming & Development 3 January 4, 2019 09:16
[OpenFOAM.org] Install openFOAM 3.0.1 in Ubuntu 16.04 LTS from Deb packs Pier84 OpenFOAM Installation 4 June 18, 2016 17:22
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 13:21
Multiple inheritance, function pointers or? ngj OpenFOAM 0 March 20, 2009 11:36


All times are GMT -4. The time now is 12:30.