|
[Sponsors] |
How does one initialise an OFstream in the constructor? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 17, 2011, 08:17 |
How does one initialise an OFstream in the constructor?
|
#1 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34 |
Hi,
I have a class which contains an OFstream member Code:
OFstream outFile_; Code:
Foam::myClass::myClass ( ... constructor arguments ... ) : outFile_("fileName") { ... main constructor here ... } I have tried initialise the OFstream object in the main constructor (not the quick way above), but it is wrong: Code:
if(Pstream::master()) { outFile_ = new OFstream("fileName"); } Philip |
|
August 17, 2011, 14:33 |
|
#2 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
You can use the conditional operator in initialization lists. Here's an example from my code:
Code:
convergence_ ( dict_.found("convergence") ? readScalar(dict_.lookup("implicitConvergence")) : defaultConvergence_ ), Code:
item ( trueOrFalseExpression ? useThisIfTrue : useThisIfFalse ), -Dave |
|
August 18, 2011, 09:48 |
|
#3 |
Super Moderator
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,097
Rep Power: 34 |
Dave,
Thanks, this looks like what I need. I tried: Code:
outFile_ ( Pstream::master() ? "fileName" : NULL ) Code:
error what(): basic_string::_S_construct NULL not valid terminate called after throwing an instance of 'std::logic_error' So as a work-around, I have done this: Code:
outFile_ ( Pstream::master() ? "fileName" : "slaveNullFile" ) Thanks for the help, Philip |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Face Set Constructor for star v4.02 | gonnafon | Siemens | 1 | June 6, 2012 10:16 |
MultiComponentMixture constructor | prashant24983 | OpenFOAM Running, Solving & CFD | 5 | February 7, 2011 16:54 |
face order in fvMesh constructor | schmittp54 | OpenFOAM Programming & Development | 2 | November 2, 2010 10:42 |
A problem about class OFstream | jennyrui2008 | OpenFOAM Running, Solving & CFD | 0 | December 5, 2008 04:55 |
Initialise Profile Data | Aloise | CFX | 3 | December 9, 2006 11:39 |