No matching function for call



  • 在向DPMFoam求解器collision model中添加一个随机函数时出现下面错误,各位老老师帮忙看看:
    添加的代码:

    label seed;
    Random randomNumber;//.H文件下的定义
    
    volumeFactor_(1.0),
    seed(1),
    randomNumber(seed),//Constructors
    
     Info<< randomNumber.scalar01() << endl;//在一个函数里输出随机数
    

    错误提示:

     error: no matching function for call to 'Foam::Random::scalar01() const'
         Info<< randomNumber.scalar01() << endl;
    
    




  • 添加了,在.H头文件上



  • 为什么
    Foam::Random::scalar01() const 有个const?



  • @星星星星晴 这我也不明白,我找了它的原函数也不是const,不知道为啥后面莫名其妙就多了一个const



  • @upc_ngh

     cachedRandom& rndGen = this->owner().rndGen();
    YY = rndGen.sample01<scalar>() * 2.0 - 1.0 + ROOTVSMALL;
    


  • @星星星星晴 好的,多谢我用您这试试看



  • @星星星星晴No matching function for call 中说:

    cachedRandom& rndGen = this->owner().rndGen();

    还是不行,一直在改,感觉调用一个很简单的函数,实现起来好难呀,昨天的方法和今天都编译不了,我把文件传上来pairCollision.zip ,哪位大佬帮忙看看:wolaile:



  • @upc_ngh
    晕 他俩都不在一个class里 怎么能互相调用呢。。
    不确定能不能过,你试试看

    template<class CloudType>
    void Foam::PairSpringSliderDashpot<CloudType>::evaluatePair
    (
        typename CloudType::parcelType& pA,
        typename CloudType::parcelType& pB
    ) const
    {
    	
    cachedRandom& rndGen = this->owner().rndGen();
    。
    。
    。
    。
    
     scalar YY = rndGen.sample01<scalar>() * 2.0 - 1.0 + ROOTVSMALL;// I want to INfo the randomnumber everytime when I call this
     //evaluatePair function.
     Info<< "Random number = " << YY << endl
    
    
    }
    


  • @星星星星晴
    好吧还是不太对,报错是下面的样子,我再试试看吧,这和课本上的C++是不太一样,多谢多谢

    In file included from ./submodels/Kinematic/CollisionModel/PairCollision/PairModel/PairSpringSliderDashpot/PairSpringSliderDashpot.T.H:186:0,
                     from ./parcels/include/makeParcelCollisionModels.H:34,
                     from parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C:34:
    ./submodels/Kinematic/CollisionModel/PairCollision/PairModel/PairSpringSliderDashpot/PairSpringSliderDashpot.T.C: In instantiation of 'void Foam::PairSpringSliderDashpot<CloudType>::evaluatePair(typename CloudType::parcelType&, typename CloudType::parcelType&) const [with CloudType = Foam::CollidingCloud<Foam::KinematicCloud<Foam::Cloud<Foam::CollidingParcel<Foam::KinematicParcel<Foam::particle> > > > >; typename CloudType::parcelType = Foam::CollidingParcel<Foam::KinematicParcel<Foam::particle> >]':
    parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C:50:58:   required from here
    ./submodels/Kinematic/CollisionModel/PairCollision/PairModel/PairSpringSliderDashpot/PairSpringSliderDashpot.T.C:301:45: error: passing 'const Foam::CollidingCloud<Foam::KinematicCloud<Foam::Cloud<Foam::CollidingParcel<Foam::KinematicParcel<Foam::particle> > > > >' as 'this' argument discards qualifiers [-fpermissive]
     cachedRandom& rndGen = this->owner().rndGen();
                                                 ^
    In file included from ./clouds/Templates/KinematicCloud/KinematicCloud.T.H:621:0,
                     from ./clouds/derived/basicKinematicCollidingCloud/basicKinematicCollidingCloud.H:36,
                     from parcels/derived/basicKinematicCollidingParcel/makeBasicKinematicCollidingParcelSubmodels.C:26:
    ./clouds/Templates/KinematicCloud/KinematicCloudI.T.H:359:28: note:   in call to 'Foam::cachedRandom& Foam::KinematicCloud<CloudType>::rndGen() [with CloudType = Foam::Cloud<Foam::CollidingParcel<Foam::KinematicParcel<Foam::particle> > >]'
     inline Foam::cachedRandom& Foam::KinematicCloud<CloudType>::rndGen()
                                ^
    /home/ofuser/blueCFD/OpenFOAM-4.x/wmake/makefiles/general:251: recipe for target '/home/ofuser/blueCFD/OpenFOAM-4.x/platforms/mingw_w64GccDPInt32Opt/src/lagrangian/intermediate/makeBasicKinematicCollidingParcelSubmodels.o' failed
    make: *** [/home/ofuser/blueCFD/OpenFOAM-4.x/platforms/mingw_w64GccDPInt32Opt/src/lagrangian/intermediate/makeBasicKinematicCollidingParcelSubmodels.o] Error 1
    


  • @upc_ngh

    好吧,我也没自己完全弄过这个东西,不过告诉你个好消息。
    再PairSpringSliderDashpot.C上 #include random.H
    然后在最下面的class:evaluatePair 尝试通过,你可以试试。

    Random rndGen(0);
    scalar samples = rndGen.scalar01();
    
    你可以看看这个例子怎么调用的random
    /opt/openfoam/OpenFOAM-4.1/applications/test/BinSum
    


  • 好的,我认真看看,非常感谢您的回答,谢谢


Log in to reply
 

CFD中文网 2016 - 2020 | 京ICP备15017992号-2