Function overloading in C++ passing arguments by value or by reference
<p>If we have this example functions code in C++</p>

<pre><code>void foo(int x)  { std::cout &lt;&lt; "foo(int)"   &lt;&lt; std::endl; }
void foo(int&amp; x) { std::cout &lt;&lt; "foo(int &amp;)" &lt;&lt; std::endl; }
</code></pre>

<p>Is it possible to difference what function to call doing any modification in the calling arguments?</p>

<p>If the function foo is called in some of these ways:</p>

<pre><code>foo( 10);

i = 10;
foo( static_cast&lt;const int&gt;(i));

foo( static_cast&lt;const int&amp;&gt;(i)); 
</code></pre>

<p>it's called the first foo overloaded function, because it can't pass by reference a const argument to a non-const parameter.
But, how would you do to call the second foo overload function?
If I call the next way:</p>

<pre><code>int i = 10;
foo( i);
</code></pre>

<p>It happens an ambiguous error because both functions are valid for this argument.</p>

<p>In this link <a href="https://stackoverflow.com/a/5465379/6717386">https://stackoverflow.com/a/5465379/6717386</a> it's explained one way to resolve it: using objects instead of built-in types and doing private the copy constructor, so it can't do a copy of object value and it has to be called the second foo overload function and passing the object by reference. But, is there any way with the built-in types? I have to change the name of function to avoid the overloading?</p>