-6

First of all, thank you for your time and consideration! I am a fortran user and quite new with c++, and I need your help to understand some bit of coding that was passed on to me. I am pasting a small part of the code that bothers me most.

tmp<volScalarField> talpha = thermo.alpha();
const volScalarField& alpha = talpha();
tmp<volScalarField> tkappa = thermo.kappa();
const volScalarField& kappa = tkappa();

volScalarField& h = thermo.he();

const volScalarField& betav = betavSolid[i];

fv::IOoptionList& fvOptions = solidHeatSources[i];

My main concern is with the '&' placed at the end of declarations, what does it mean ? Also, why create a tmp field talpha for instance and declare next alpha=talpha ? Why not allocating thermo.alpha() to alpha directly ?

dandan78
  • 12,893
  • 12
  • 63
  • 75
SimoMJ
  • 11
  • 2

1 Answers1

1

This is a reference type.

C++ has three basic types: values, pointers and references. Reference type is similar to pointer, with two exceptions:

  • reference has to be initialized when created (via assign operation on a value or another reference),
  • reference cannot be changed to refer to another variable (similarly to "const pointer"),
  • references use "dot" operator like values for struct and classes fields instead of "arrow" as it is with pointers.
hauron
  • 4,348
  • 3
  • 34
  • 52