pch2
is a char*
, not a char const*
. You cannot bind a link of type char const*&
to a pointer of type char*
, so the following will be poorly formed:
char* p(0); char const*& r(p);
Similarly, if your function was declared as void f(char const*& pch)
, you would not be able to call it with the char*
argument due to a const-qualifier mismatch.
The reason your example works is because the const link can bind to a temporary one, and the compiler can create a temporary copy of your char*
pointer, specify a temporary char const*
type, and bind the pch
link to this temporary pointer.
source share