-3

First of all, for people who want to vote this down, note that the member variables were not shown in the class reference and the link to the header file was broken!

I have the following constructor:

    Foam::IOobject::IOobject
143 (
144  const word& name,           
145  const fileName& instance,   
146  const objectRegistry& registry,   
147  readOption ro,
148  writeOption wo,
149  bool registerObject
150 )
151 :                               
152  name_(name),                         
153  headerClassName_(typeName),
154  note_(),
155  instance_(instance),
156  local_(),
157  db_(registry),
158  rOpt_(ro),
159  wOpt_(wo),
160  registerObject_(registerObject),
161  objState_(GOOD)
162 {
163  if (objectRegistry::debug)
164  {
165  Info<< "Constructing IOobject called " << name_
166  << " of type " << headerClassName_
167  << endl;
168  }
169 }

As far as I have read initializer are used to:

  • Invoke base class constructors from a derived class
  • Initialize member variables of the class

See: https://stackoverflow.com/questions/2445330/importance-of-a-singlecolon-in-c

I just can't figure out what the elements in the examples constructors initializer are for since they are no member variables of the class IOobject and aren't constructors of derived classes. Can someone tell me what these initializer elements are for?

greetings streight

Community
  • 1
  • 1
Streight
  • 811
  • 4
  • 15
  • 28
  • 3
    Are you sure these aren't member variables of the class? You only posted the constructor's implementation, can you add the definition of the class (from its header file)? – Frédéric Hamidi Nov 06 '13 at 13:43
  • 2
    If there were no data members or base classes, the code wouldn't compile. – juanchopanza Nov 06 '13 at 13:44
  • It looks like `name_` might be a member variable, in which case, the base class, if there is one, is default initialised. – quamrana Nov 06 '13 at 13:46
  • See: http://foam.sourceforge.net/docs/cpp/a01015.html#details – Streight Nov 06 '13 at 13:49
  • @Luecking: Great comment, note that the member variables were not shown in the class reference and the link to the header file was broken! – Streight Nov 06 '13 at 14:19
  • @Streight: If the "link to the header file was broken" then how do you know that " they are no member variables of the class IOobject and aren't constructors of derived classes?" – John Dibling Nov 06 '13 at 14:34
  • @John Dibling: I thought they weren't because they weren't listed in the class reference and the derived classes are shown in the IOobject class reference (diagram at the beginning). – Streight Nov 06 '13 at 14:37

2 Answers2

2

the IOobject class has the following members defined(header file):

127  //- Name
128  word name_;
129 
130  //- Class name read from header
131  word headerClassName_;
132 
133  //- Optional note
134  string note_;
135 
136  //- Instance path component
137  fileName instance_;
138 
139  //- Local path component
140  fileName local_;
141 
142  //- objectRegistry reference
143  const objectRegistry& db_;
144 
145  //- Read option
146  readOption rOpt_;
147 
148  //- Write option
149  writeOption wOpt_;
150 
151  //- Register object created from this IOobject with registry if true
152  bool registerObject_;
153 
154  //- IOobject state
155  objectState objState_;

Take a look at the header file here: http://foam.sourceforge.net/docs/cpp/a06519_source.html

and here is the constructor signature

IOobject    
(
    const word &        name,
    const word &        instance,
    const fileName &        local,
    const objectRegistry &      registry,
    readOption          r = NO_READ,
    writeOption         w = NO_WRITE,
    bool            registerObject = true
)

and there is documentation available here

Let me know if you need more details, I will try and hunt more down for you.

GMasucci
  • 2,834
  • 22
  • 42
2

From your link, if you navigate to the header file, it shows the members, so it is clear that there is no base class and the initialiser list in the constructor initialises members alone.

127  //- Name
128  word name_;
129 
130  //- Class name read from header
131  word headerClassName_;
132 
133  //- Optional note
134  string note_;
135 
136  //- Instance path component
137  fileName instance_;
138 
139  //- Local path component
140  fileName local_;
141 
142  //- objectRegistry reference
143  const objectRegistry& db_;
144 
145  //- Read option
146  readOption rOpt_;
147 
148  //- Write option
149  writeOption wOpt_;
150 
151  //- Register object created from this IOobject with registry if true
152  bool registerObject_;
153 
154  //- IOobject state
155  objectState objState_;
quamrana
  • 37,849
  • 12
  • 53
  • 71
  • Thx, I see now. It wasn't my fault that the member variables are not shown in the class reference and the link I firstly used to the header file was broken. – Streight Nov 06 '13 at 14:12