CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

What is the role of tmp%2360T class objects

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   September 17, 2008, 03:29
Default Dear OF users, I have a lit
  #1
New Member
 
nicasch
Join Date: Mar 2009
Posts: 23
Rep Power: 8
nicasch is on a distinguished road
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
private:
dimensionedScalar s_;
volScalarField F_;

public:
// 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.
nicasch is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
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


All times are GMT -4. The time now is 06:30.