-3

首先,对于想要投​​反对票的人,请注意成员变量未显示在类引用中,并且指向头文件的链接已损坏!

我有以下构造函数:

    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 }

据我所知,初始化程序用于:

  • 从派生类调用基类构造函数
  • 初始化类的成员变量

请参阅:https ://stackoverflow.com/questions/2445330/importance-of-a-singlecolon-in-c

我只是无法弄清楚示例构造函数初始化程序中的元素是什么,因为它们不是类的成员变量,IOobject也不是派生类的构造函数。有人能告诉我这些初始化元素是干什么用的吗?

直接问候

4

2 回答 2

2

IOobject 类定义了以下成员(头文件):

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_;

看看这里的头文件:http: //foam.sourceforge.net/docs/cpp/a06519_source.html

这是构造函数签名

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

并且有可用的文档here

如果您需要更多详细信息,请告诉我,我会尽力为您寻找更多信息。

于 2013-11-06T13:51:58.070 回答
2

从您的链接中,如果您导航到头文件,它会显示成员,因此很明显没有基类,并且构造函数中的初始化列表单独初始化成员。

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_;
于 2013-11-06T13:54:44.310 回答