|September 17, 2008, 03:29||
Dear OF users, I have a lit
Join Date: Mar 2009
Posts: 23Rep Power: 10
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:
// Private data
// Member functions
tmp<volscalarfield> sF() const
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.
|Thread||Thread Starter||Forum||Replies||Last Post|
|Understanding tmp%2360T classes||nadine||OpenFOAM Running, Solving & CFD||14||January 22, 2009 10:25|
|Invalid pointer handling in tmp%2360T class||mbeaudoin||OpenFOAM||1||April 24, 2007 12:57|
|The Role of CFD (non-CFD question)||M||Main CFD Forum||12||September 12, 2005 17:54|
|Role of divergence||shekharc||Main CFD Forum||7||July 5, 2005 12:08|