【发布时间】:2014-12-16 21:10:39
【问题描述】:
OpenFOAM 库定义了两种类型,volMesh 和surfaceMesh,它们都继承自GeoMesh<fvMesh>。我想定义一个接受参数的函数:
void foo(GeometricField<vector, fvsPatchField, GeoMesh<fvMesh> >& field) { ... }
但是,当我尝试调用该函数时,g++ 会给出错误“引用类型的初始化无效”:
// surfaceVectorField is a typedef GeometricField<vector, fvsPatchField, surfaceMesh>
surfaceVectorField Uf( /* initialisation arguments */ );
foo(Uf);
来自Java背景,这个问题似乎类似于忘记使用诸如
之类的声明void foo(GeometricField<vector, fvsPatchField, ? extends GeoMesh<fvMesh>> field) { ... }
如果可能,我需要避免使用 C++11 特有的功能。
【问题讨论】:
-
你能多加一点代码吗,例如你如何尝试调用你的函数?
-
是函数调用
foo()的错误还是Uf的变量定义错误? stackoverflow.com/questions/9285627/… -
可能它无法将您的surfaceMesh参数转换为
GeoMesh<fvMesh>,或者整个构造都无法转换为对正确复杂类型的引用。 -
@RichardChambers:错误来自对
foo()的调用 -
在初始化surfaceVectorField时尝试将surfaceMesh显式转换为
GeoMesh<fvMesh>。