How to call a non-const function within a const function (C++)

后端 未结 7 747
天命终不由人
天命终不由人 2020-12-10 01:06

I have a legacy function that looks like this:

int Random() const
{
  return var_ ? 4 : 0;
}

and I need to call a function within that lega

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 01:49

    if it's really a random number generator, then the number generation code/state could likely be placed in a class-local static generator. this way, your object is not mutated and the method may remain const.

提交回复
热议问题