CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   What is the role of tmp%2360T class objects (

nicasch September 17, 2008 03:29

Dear OF users, I have a lit
Dear OF users,

I have a little doubt on using tmp<t> objects and could use some help. I understand that a tmp<t> object is used to somehow automatically allocate and deallocate a temporary object. Many function members in OF classes use a tmp<t> objects as a return type, for example:

class someClass
// Private data
dimensionedScalar s_;
volScalarField F_;

// Constructor
// Destructor
// etc...

// Member functions
tmp<volscalarfield> sF() const
return s_*F_;

After calling the function sF() in some calculation in main() e.g. fvc::interpolate(someClass.sF()), a volScalarField is created within the function sF() as a product s_*F_. But, why should the return type from the function not be simply a const volScalarField& instead of tmp<volscalarfield>? The tmp<t> object stores a pointer to a temporary object in addition to its reference. But, since the product s_*F_ is already a temporary volScalarField it should go out of scope after leaving the function sF(). Does this means that the pointer to s_*F_ is reset to NULL immediately after return from function?

What exactly is being returned from this kind of functions and what are generally the benefits of using tmp<t> objects?

Thanks for any advice/explanation and best regards to all.

All times are GMT -4. The time now is 14:21.