function has effects on the other functions that run before it did
<pre><code>{
    int X = hfilter * threebythree(i,j,getData(),getNumRows(),getNumCols());
    int Y = vfilter * threebythree(i,j,getData(),getNumRows(),getNumCols());
    int value = floor(sqrt(X*X+Y*Y));

    //evil setValue function
    setValue(i,j,value);
}

Image Image::threebythree(int globali,int globalj, int** matrix,int row,int col)
{
    Image neighbor;
    neighbor.setNumRows(3);
    neighbor.setNumCols(3);
    neighbor.AllocateMem();

    for(int i=0; i&lt;3; ++i)
    {
        for(int j=0; j&lt;3; ++j)
        {

            if((i+globali-1 &gt;=0) &amp;&amp; (j+globalj-1 &gt;=0) &amp;&amp; (i+globali-1 &lt; row) &amp;&amp; (j+globalj-1 &lt; col))
            {
                //cout&lt;&lt; matrix[i+globali-1][j+globalj-1] &lt;&lt; " , ";
                neighbor.setValue(i,j,matrix[i+globali-1][j+globalj-1]);
            }
            else
            {
                neighbor.setValue(i,j,0);
            }
        }
    }


    for(int i=0; i&lt;3; ++i)
    {
        for(int j=0; j&lt;3; ++j)
        {
            cout &lt;&lt; neighbor.getValue(i,j)&lt;&lt; ",";
        }
        cout &lt;&lt; endl;
    }

    return neighbor;
}



void Matrix::setValue(int i, int j, int value)
{
    data[i][j] = value;
}
</code></pre>

<p>What I'm doing here is that <code>threebythree()</code> generates a 3x3 matrix when traversing through a big matrix like 100x100.</p>

<p>Everything works fine if comment out the: </p>

<pre><code>setValue(i,j,value);
</code></pre>

<p><code>threebythree()</code> prints out a nice 3x3 matrix like: </p>

<pre><code>47,50,0,
50,55,0,
0,0,0,
</code></pre>

<p>But <strong>with</strong> <code>setValue(i,j,value)</code>, which runs after the <code>threebythree()</code>, the 3x3 matrix suddenly changed to:</p>

<pre><code>35384,-2147483648,0,
42428,55,0,
0,0,0,
</code></pre>

<p>How could a function have impact on the functions that are executed before it did?</p>
