c++ reference parameter not updated
<p>I'm trying to write a simple function to extract the next number from an expression in a string and my problem is that the reference parameter ioIsValidExpression is not being updated after the function exits. It looks like I am actually referencing the correct variable (and not a temporary) since the addresses of test3 (as it is called before calling getNextNumber(...)) and ioIsValidExpression (its name when inside the function) are the same.</p>

<p>I expect this to be an embarassing mistake somewhere but I'm getting nowhere trying to figure this one out; I've included my int main and int getNextNumber with a comment line where I return a value from the function.</p>

<pre><code>int getNextNumber(std::string&amp; iExpression, int&amp; ioLoopShift, bool&amp; ioIsValidExpression)
{
    //spaces are ignored, a minus is a unary minus (so must be seated next to a number (no spaces between '-' and number))
    int length = iExpression.size(); //evaluate only once
    bool unaryMinusFound = false;
    bool numberFound = false;

    int oSubExpression = 0;
    for(int i =0; i &lt; length; i++)
    {
        if((int)iExpression[i] == 32)
        {
            if(!numberFound)
            {
                if(!unaryMinusFound)
                {
                    continue;
                }
                else
                {
                    ioIsValidExpression = false;
                    td::cout &lt;&lt; "address of ioIsValidExpression: " &lt;&lt; &amp;ioIsValidExpression &lt;&lt; ", value: " &lt;&lt; ioIsValidExpression &lt;&lt; "\n";
                    return 0;
                }
            }
            else
            {
                return unaryMinusFound? -1 * oSubExpression: oSubExpression;
            }
        }
        if((int)iExpression[i] == 45 &amp;&amp; !unaryMinusFound)
        {
            unaryMinusFound = true;
            continue;
        }
        if((int)iExpression[i] &gt;= 48 &amp;&amp; (int)iExpression[i] &lt;= 57)
        {
            numberFound = true;
            oSubExpression = (int)(iExpression[i]-48) + 10*oSubExpression;
            ioLoopShift++;
            continue;
        }
        else
        {
            //garbage characters
            ioIsValidExpression = false;
            return 0;
        }
    }
    return unaryMinusFound? -1 * oSubExpression: oSubExpression;
}
</code></pre>

<p>int main:</p>

<pre><code>int main(int argc, char* argv[])
{
    std::string test = " - 45 &amp; ";
    int test2 = 0;
    bool test3 = true;
    std::cout &lt;&lt; getNextNumber(test,test2,test3) &lt;&lt; ", address of test3: " &lt;&lt; &amp;test3 &lt;&lt; ", value: " &lt;&lt; test3 &lt;&lt; "\n";

    return 0;
}
</code></pre>

<p>output from running the program: </p>

<pre><code>address of ioIsValidExpression: 0xbf86e58f, value: 0
0, address of test3: 0xbf86e58f, value: 1
</code></pre>
