@yzxwh
- 看起来没问题,我也按照你的问题写了个简单例子测试,输出结果是正确的。
#include "fvCFD.H"
class Parent {
protected:
int protectedVar = 5;
public:
void modifyVariable() {
int tmp = 10;
int tmp2 = tmp;
Parent::protectedVar = tmp;
Info << "tmp2 = " << tmp2 << nl << endl;
Info << "Parent::protectedVar = " << Parent::protectedVar << nl << endl;
}
};
class Child : public Parent {
public:
void accessParentFunction() {
Parent::modifyVariable();
Info << "Child::protectedVar = " << Parent::protectedVar << nl << endl;
}
};
int main(int argc, char *argv[])
{
#include "setRootCase.H"
Child child;
child.accessParentFunction();
Info<< "End\n" << endl;
return 0;
}
- 看到
velocityMotionsolver.H
函数中有个返回引用函数:pointVectorField& pointMotionu()
,试试能不能创建一个引用,然后修改引用的值,看看结果会不会变化。
pointVectorField& pointMotionURef = pointMotionU();
pointMotionURef = tempPointMotionU;
Info << "pointMotionURef = " << pointMotionURef << endl;
Info << "pointMotionU = " << pointMotionU_ << endl;