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

Access private data member

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

Like Tree1Likes
  • 1 Post By denyo

Reply
 
LinkBack Thread Tools Display Modes
Old   December 17, 2008, 08:12
Default Hi everyone, Just a more '
  #1
Senior Member
 
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 338
Rep Power: 9
lr103476 is on a distinguished road
Hi everyone,

Just a more 'general' C++ programming question. What is the best way to access private data member used in i.e. dynamicBodyFvMesh from your application, i.e. icoDyMFoam.C ?

Regards, Frank
__________________
Frank Bos
lr103476 is offline   Reply With Quote

Old   December 17, 2008, 10:08
Default Hi Frank, private data are
  #2
New Member
 
Daniel Conrad
Join Date: Mar 2009
Posts: 1
Rep Power: 0
denyo is on a distinguished road
Hi Frank,

private data are accessed via a public function, which returns the value of a private variable (by convention indicated with underscore: privateVariable_) or a reference (&privateVariable_) to it.
Look through any .H file to look up you possibilities to access private data using function declared as public memberfunctions.

dynamicBodyFvMesh is a meshtype and needed for the runTimeSelectionTable. Nevertheless it is derived from fvMesh. Goto src/finiteVolume/fvMesh.H to see your options.

best regards,
Daniel
Pascal_doran likes this.
denyo is offline   Reply With Quote

Old   December 18, 2008, 04:02
Default Hi Frank, Having seen your
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 777
Rep Power: 18
olesen will become famous soon enough
Hi Frank,

Having seen your talk in Milano, I suspect that you're probably okay with C++ per se, but for your current question:

if you need read-only access to a private member, just add a public const member to the header, eg.

const foo& bar() const
{
return bar_;
}

and let the OpenCFD guys know that you need read access to the data for whatever reason so they can add it to the header for everyone.

If you need write-access to the data member, you should either question if this is the correct approach at all, or if you actually need a derived class. If the latter is the case, it would be reasonable to provide a protected write-accessor so that your derived class can monkey with the data.

One important note, however: be careful about mixing const/non-const and private/public declarations for the same member signature. If a non-const member is declared private and a const member of the same name and signature is declared public, the compiler cannot tell which one is meant when compiling your application. A simplified explanation: the first compiler pass just takes the best signature, but doesn't bother to work out if const access would have sufficed and you'll get lots of compiler complaints.
olesen 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
question on data access in parallel computation wangrensong FLUENT 0 January 7, 2009 04:24
UDF Data Access Macro Woo Meng Wai FLUENT 0 November 6, 2007 21:23
UDF's to access Postprocess data ivor FLUENT 1 December 15, 2003 11:07
access to FIDAP-internal data from within a UDF II Ingo Meisel FLUENT 1 April 23, 2001 11:47
access to FIDAP-internal data from within a UDF Ingo Meisel FLUENT 0 April 17, 2001 11:58


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