I guess I must have misread the question because I ended up answering what difference it is between using const inside the parameter list compared to using it after.
If you're writing a function that should modify a class object you can either write it as a "member function" (inside the class) or as a "free function" (outside the class).
#include <iostream>
struct S
{
int x;
// member function
void foo()
{
x = 5;
}
};
// free function
void foo(S& s)
{
s.x = 5;
}
int main()
{
S s;
s.foo(); // calls the member function
foo(s); // calls the free function
}
These two functions named "foo" are more or less identical if we ignore the syntactical difference. The object is essentially "passed" to the member function using an implicit this parameter.
Now, what if we want to write a function "bar" that does not modify the object, and that can be used with objects declared as const?
With a free function it's easy, just mark the parameter reference as const.