Closed HaroldHatchNIST closed 5 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
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?