大家好、各位大佬好,咨询一个编译函数调用问题
我在别的论坛找到了一个在求解器中定义函数编译调用的例子如下:
//fun.H
#ifndef fun_H
#define fun_H
#include "scalar.H"
#include "vector.H"
namespace Foam
{
vector TestMe(const vector& myvec);
}
#endif
以及
//fun.C
#include "fun.H"
Foam::vector Foam::TestMe(const vector& myvec)
{
Info<< "Hello from TestMe" << endl;
Info<< "vector: " << myvec << endl;
}
然后在主函数里面调用 "fun.H"就行了。
#include "fun.H"
using namespace Foam;
int main(int argc, char *argv[])
{
vector A(1,2,3);
Info<< "Hello from the main()" << endl;
return 0;
}
我的思路就是直接在fun.H中写我想调用的代码。比如在“KinematicCloudI.H”文件中定义的
template<class CloudType>
inline const Foam::tmp<Foam::volVectorField>
Foam::KinematicCloud<CloudType>::UPar() const
{
tmp<volVectorField> tUPar
(
volVectorField::New
(
this->name() + ":UPar",
mesh_,
dimensionedVector(dimVelocity, vector(0,0,0)),
extrapolatedCalculatedFvPatchVectorField::typeName
)
);
volVectorField& UPar = tUPar.ref();
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
{
const parcelType& p = iter();
const label celli = p.cell();
UPar[celli] += (p.U())/(p.nParticle());
}
UPar.primitiveFieldRef() /= 1;//mesh_.V();
UPar.correctBoundaryConditions();
return tUPar;
}
我直接移植过来,编译出现了如下错误:
fun.H:16:41: error: no ‘const Foam::tmp<Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> > Foam::KinematicCloud<CloudType>::UPar() const’ member function declared in class ‘Foam::KinematicCloud<CloudType>’
Foam::KinematicCloud<CloudType>::UPar() const
我尝试把“KinematicCloudI.H”里面的头文件粘上去也通过不了,应该怎么修改以及加一些什么内容呢?
谢谢