|
[Sponsors] |
August 23, 2016, 23:24 |
MultiRegionSetFields.C
|
#1 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Dear Fellows
I am looking at multiRegionSetFields.C file inside OF and there are some lines that I can not understand. The followings start from line 129: Code:
class iNew { const fvMesh& mesh_; const labelList& selectedCells_; public: iNew(const fvMesh& mesh, const labelList& selectedCells) : mesh_(mesh), selectedCells_(selectedCells) {} In the above , the class iNew has two constant private objects (mesh_ and selectedCells_) from fvMesh and labelList classes and a constructor (iNew) which has mesh and selectedCells as input arguments. However what is that ":" and these two lines: Code:
: mesh_(mesh), selectedCells_(selectedCells) Why fvMesh and labelList classes are defined as References: Code:
const fvMesh& mesh_; const labelList& selectedCells_; |
|
August 24, 2016, 13:17 |
|
#2 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Dear Fellows
I figured out my first question answer. that Code:
: mesh_(mesh), selectedCells_(selectedCells) Code:
mesh_=mesh; seectedCells_=selectedCells; Why fvMesh and labelList classes are defined as References: Code:
const fvMesh& mesh_; const labelList& selectedCells_; |
|
August 27, 2016, 14:48 |
|
#3 | |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21 |
Quote:
Because when you construct an abject of this class you want these member variables to point to the existing objects not to create new ones, right. If they were not references but values then the constructor would have to create new copies. |
||
August 27, 2016, 15:14 |
|
#4 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Thanks Sergei.
Just for clarifying: HTML Code:
Because when you construct an abject of this class you want these member variables to point to the existing objects not to create new ones, right. If they were not references but values then the constructor would have to create new copies. Code:
const fvMesh& mesh_; const labelList& selectedCells_; Last edited by babakflame; August 27, 2016 at 17:47. |
|
August 27, 2016, 19:02 |
|
#5 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21 |
I believe mesh_ and selectedCells_ are called "member variables" and they are part of an object of iNew class. The word "variable" might imply that it can vary or be modified, but no, variable can be constant as well. And to confuse you even more, member variables are objects at the same time
|
|
|
|