我有一个看起来像这样的遗留函数:
int Random() const
{
return var_ ? 4 : 0;
}
我需要在该遗留代码中调用一个函数,使其现在看起来像这样:
int Random() const
{
return var_ ? newCall(4) : 0;
}
问题是我收到了这个错误:
In member function 'virtual int Random() const':
class.cc:145: error: passing 'const int' as 'this' argument of 'int newCall(int)' discards qualifiers
现在我知道为了修复这个错误,我可以创建newCall()
一个 const 函数。但是后来我必须进行几个newCall()
函数调用,所以现在我必须将所有这些函数调用都设为 const。依此类推,直到最终我觉得我的程序的一半将是 const。
我的问题:有没有办法在 Random() 中调用不是 const 的函数?或者是否有人对如何newCall()
在Random()
不使我的程序一半变为常量的情况下实现内部有任何想法。
谢谢
-乔希