How to pass a bool variable by reference in a non-bool function?
<p>I looked <a href="http://cboard.cprogramming.com/cplusplus-programming/112625-passing-boolean-var-reference.html" rel="nofollow noreferrer">at how to pass a bool by reference</a>, but that function returned the bool inside of it. I also looked <a href="https://stackoverflow.com/questions/11932614/in-c-is-it-bad-to-pass-a-const-bool-by-reference">here on stack overflow</a>, but the suggestions made by the commenters did not improve my situation. So, </p>

<p>I have a function:</p>

<pre><code>myTreeNode* search_tree(myTreeNode *test_irater, char p_test, bool &amp;flag)
</code></pre>

<p>That obviously returns a <code>myTreeNode*</code> type. I also have a variable, <code>bool flag</code> that I want to change the value of within the function. However, when I try to pass the bool by reference, I get an error message of </p>

<blockquote>
  <p>error: invalid initialization of non-const reference of type 'bool&amp;'
  from an rvalue of type 'bool*'|</p>
</blockquote>

<p>How do I go about passing a bool by reference without returning a bool? I am running on the latest version of CodeBlocks, if that is relevant.</p>

<p>Edit: code</p>

<pre><code>myTreeNode* search_tree(myTreeNode *test_irater, char p_test, bool &amp;flag)
{
    switch(p_test) 
    {
    case 'a':
        if (test_irater-&gt;childA == NULL)
            flag = false;
        else {
            test_irater = test_irater-&gt;childA;
            flag = true;
        }
        break;
    case 't':
        if (test_irater-&gt;childT == NULL)
            flag = false;
        else {
            test_irater = test_irater-&gt;childT;
            flag = true;
        }
        break;
    case 'c':
        if (test_irater-&gt;childC == NULL)
            flag = false;
        else {
            test_irater = test_irater-&gt;childC;
            flag = true;
        }
        break;
    case 'g':
        if (test_irater-&gt;childG == NULL)
            flag = false;
        else {
            test_irater = test_irater-&gt;childG;
            flag = true;
        }
        break;
    }
    return test_irater;
}
</code></pre>

<p>called like:</p>

<pre><code>test_irater = search_tree(test_irater, p_test, &amp;flag); 
</code></pre>