Non-const reference to a non-const pointer pointing to the const object
<p>In simple words I have a simple pointer:</p>

<pre><code>int* a;
</code></pre>

<p>now, I would like to change value of this pointer. I want to do this in a function. Function assures, that it will not change object, that pointer points to, but will change a pointer itself. This is why I would like this function to take argument like: non-const reference (because value of pointer will be changed) to the non-const pointer(pointer itself can be changed) pointing to const object (function assures, that object, that pointer points to will not be changed).</p>

<p>The simplest function would be:</p>

<pre><code>void function(const int*&amp; a){
    a = 0;
}
</code></pre>

<p>but when I try to call this function:</p>

<pre><code>int main(){
    int* a;
    function(a);
    return 0;
}
</code></pre>

<p>Compiler is unhappy and says:</p>

<blockquote>
  <p>invalid initialization of non-const reference of type 'const int*&amp;' from an rvalue of type 'const int*'
    function(a);</p>
</blockquote>

<p>I cannot quite understand this error, as for me there is no rvalue involved (I am passing a reference to object, that already exists on the stack.)</p>

<p>Question is, how can I do it properly?</p>

<p>Example can be found here: <a href="https://ideone.com/D45Cid" rel="nofollow noreferrer">https://ideone.com/D45Cid</a></p>

<hr>

<p>EDIT:</p>

<p>It was suggested, that my question is simillar to the <a href="https://stackoverflow.com/questions/2220916/why-isnt-it-legal-to-convert-pointer-to-pointer-to-non-const-to-a-pointer-to">Why isn&#39;t it legal to convert &quot;pointer to pointer to non-const&quot; to a &quot;pointer to pointer to const&quot;</a></p>

<p>My question is different as I do not use pointer to pointer I use only pointer to object/value and store reference to it, therefore situation like in the answer to that question:</p>

<pre><code>const char c = 'c';
char* pc;
const char** pcc = &amp;pc;   // not allowed
*pcc = &amp;c;
*pc = 'C';                // would allow to modify a const object
</code></pre>

<p>Is impossible in my case, as I cannot dereference the top level pointer (I do not have such a pointer).</p>

<p>Moreover I questioned about nice and clean solution to this problem, which is not covered in a question</p>