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

后端 未结 7 727
天命终不由人
天命终不由人 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:43

    int Random() const
    {
      return var_ ? const_cast(this)->newCall(4) : 0;
    }
    

    But it's not a good idea. Avoid if it's possible!

提交回复
热议问题