L
ljh131
i have a simple question on passing the array to the reference to
pointer.
here is some code.
void donothing(int*& testarray) {}
int main()
{
int k[8];
donothing(k); // error!
return 0;
}
compiler says passing the array to reference to pointer cannot be
done. because k is the array and 'donothing' function takes reference
to pointer.
but i want to know why exactly c++ prohibits this casting. someone say
array should be considered as 'const pointer'.
and if this casting is illegal, we can change the testarray in the
function 'donothing' and it leads changing the address of 'k' in the
main function.
if you have an idea, just tell me know your opinion, thanks in
advance.
pointer.
here is some code.
void donothing(int*& testarray) {}
int main()
{
int k[8];
donothing(k); // error!
return 0;
}
compiler says passing the array to reference to pointer cannot be
done. because k is the array and 'donothing' function takes reference
to pointer.
but i want to know why exactly c++ prohibits this casting. someone say
array should be considered as 'const pointer'.
and if this casting is illegal, we can change the testarray in the
function 'donothing' and it leads changing the address of 'k' in the
main function.
if you have an idea, just tell me know your opinion, thanks in
advance.