即時通過遞歸,並想知道是否可以改變參考參數,並在函數內給予不同的值,並遞歸返回到同一個函數時,值會改變。這是我的問題,導致它不編譯。 這裏有一個例子:引用參數和遞歸?
bool findnum_recur (int wanted, int & num)
{
// if i want to increment num and call the function recursively
/*like this : */
findnum_recur (wanted, num+1);
// its giving me error, why and is there an alternative way
}
'num + 1'不是左值引用,請嘗試'++ num'。並且被警告,**號**被修改。 – WhozCraig
@NathanOliver我的意思是'num ++; findnum_recur(想,NUM);'。無論如何,評論仍然存在的唯一原因是因爲我懶得刪除它:P – user463035818