错误:将类型'Foam :: Field <double>&'的引用绑定到'const Foam :: Field <double>'会丢弃限定符

时间:2020-01-05 16:52:17

标签: c++

我遇到了一个经典的编译错误,表示我忽略了对象的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()吗?

0 个答案:

没有答案