Every time I try to compile my code I get error:
cannot convert parameter 1 from \'int *\' to \'int *&\'
The test code looks like this:
&myval
is an rvalue (of type int*
), because it's a temporary. It's a pointer, but you cannot modify it, because it's just created on the fly. Your function set
however requires a non-const reference, so you cannot pass it a temporary.
By contrast, pMyVal
is a named variable, thus an lvalue, so it can be passed as a non-constant reference.