Search code examples
c++overridingopenfoam

openfoam C++ operator& override


template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>> operator&
(
   const fvMatrix<Type>&,
   const tmp<GeometricField<Type, fvPatchField, volMesh>>&
);

Could anyone help me understand this override function in OpenFoam? As we know, operator& override should not have two parameters. So, I am confused. And do anyone know how to use this override function? Please give me a simple example, if you are not busy? Thanks.


Solution

  • As we know, operator& override should not have two parameters.

    Not true.

    The unary operator& and the binary operator& have two different meanings.

    The unary operator& is the equivalent of the address-of operator while the binary operator& is the equivalent of the bitwise AND operator.

    For reasons that are not obvious to me, the posted code defines an overload of the binary & operator between a fvMatrix<Type> and a tmp<GeometricField<Type, fvPatchField, volMesh>>.

    Syntactically speaking, the usage would be:

    fvMatrix<Type> var1{};
    tmp<GeometricField<Type, fvPatchField, volMesh>> var2{};
    
    auto var3 = var1 & var2;