usnistgov / feasst

The Free Energy and Advanced Sampling Simulation Toolkit (FEASST) is a free, open-source, modular program to conduct molecular and particle-based simulations with flat-histogram Monte Carlo methods.
http://pages.nist.gov/feasst
Other
33 stars 13 forks source link

Const protected/private variables and functions #1

Closed HaroldHatchNIST closed 5 years ago

HaroldHatchNIST commented 7 years ago

Some protected variables may be set to const in the constructor. For example, dimen_ in Space. But then how do I set them upon construction with a restart file?

HaroldHatchNIST commented 7 years ago

I would like to open up this issue to include also functions which should be declared const. This is more an open-ended issue that may not be resolved. My working method thus far is to not declare many things const that ideally would be const.

Here is an example of a const function that fails, in this case because the random number generator is modified.

  /// Return the index of a randomly selected moleule of type iMolType.
  int randMolofType(const int iMolType) const;
/home/hwh/feasst/src/space.cc: In member function ‘int feasst::Space::randMolofType(int) const’:
/home/hwh/feasst/src/space.cc:3941:37: error: passing ‘const feasst::Space’ as ‘this’ argument of ‘int feasst::BaseRandom::uniformRanNum(int, int)’ discards qualifiers [-fpermissive]
     iMol = uniformRanNum(0, nMol()-1);
                                     ^
make[3]: *** [CMakeFiles/unittest.dir/home/hwh/feasst/src/space.cc.o] Error 1