Take note of the following C++ code:
#include <iostream>
using std::cout;
int foo (const int);
int main ()
{
cout << foo(3);
}
int foo (int a)
{
a++;
return a;
}
Notice that the prototype of foo() takes a const int and that the definition takes an int. This compile without any errors…
Why are there no compilation errors?
Because it doesn’t matter to the caller of the
foofunction whetherfoomodifies its copy of the variable or not.Specifically in the C++03 standard, the following 2 snippets explain exactly why:
C++03 Section: 13.2-1
C++03 Section: 13.1-3