我遇到了一个经典的编译错误,表示我忽略了对象的const属性:
In file included from lnInclude/RBFInterpolation.H:172:0,
from toto.H:46,
from toto.C:26:
lnInclude/RBFInterpolationTemplates.C: In instantiation of 'Foam::tmp<Foam::Field<Type> > Foam::RBFInterpolation::interpolate(const Foam::Field<Type>&) const [with Type = double]':
toto.C:873:77: required from here
lnInclude/RBFInterpolationTemplates.C:65:18: error: binding reference of type 'Foam::Field<double>&' to 'const Foam::Field<double>' discards qualifiers
Field<Type>& result = tresult();
这是我称为插值的方法:
void Foam::toto::calcPtarget(const volScalarField& PIn)
{
scalarField& ctrlField_ = ctrlField();
forAll(tocPress, toCellI)
{
label cellI = tocPress[toCellI];
point curNode_ = meshRef_.cellCentres()[cellI];
controlPoints_[cellI] = curNode_;
ctrlField_[cellI] = Pref[cellI];
}
vectorField toInterPoints_ = interSurf_.faceCentres();
forAll(toInterPoints_, faceCentreI)
{
dataPoints_[faceCentreI] = toInterPoints_[faceCentreI];
}
scalarField& controlField = ctrlField_;
scalarField interpolatedMotion = interpolation_.interpolate(controlField);
}
然后该方法自我插值:
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::RBFInterpolation::interpolate
(
const Field<Type>& ctrlField
) const
{
tmp<Field<Type> > tresult
(
new Field<Type>(dataPoints_.size(), pTraits<Type>::zero)
);
Field<Type>& result = tresult();
return tresult;
}
我试图在插头中将插补运动声明为const甚至ctrlField作为可变的const,并使用它而不成功。另一种选择是从const方法中调用interpolate_.interpolate()吗?