c++ - Passing by reference issue? -


the problem trying pass array char arr[6] = {"1","2",etc.} function takes parameter void foo(char* &arr,...) , not work. can explain me please ?

char arr[6] array.

char* &arr a(n lvalue) reference pointer.

now, since argument not of correct type, has converted. array implicitly decays (decaying kind of conversion) pointer first element.

but decayed pointer temporary (an rvalue). non-const lvalue references can not refer rvalues, ill-formed call foo array argument.


you can create pointer variable; can passed foo:

char* ptr = arr; foo(ptr, ...); 

the function may modify pointer (i.e. make point other char object), since reference non-const.


ps. there wrong initialization of array. "1" , "2" not char objects.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -