c++ - What does *& mean in a function parameter -
if have function takes int *&
, means? how can pass int or pointer int function?
function(int *& mynumber);
whenever try pass pointer function says:
error: no matching function call 'function(int *)' note: candidate 'function(int *&)'
it's reference pointer int. means function in question can modify pointer int itself.
you can pass pointer in, 1 complication being pointer needs l-value, not r-value, example
int myint; function(&myint);
alone isn't sufficient , neither 0/null allowable, as:
int myint; int *myintptr = &myint; function(myintptr);
would acceptable. when function returns it's quite possible myintptr
no longer point pointing to.
int *myintptr = null; function(myintptr);
might make sense if function expecting allocate memory when given null pointer. check documentation provided function (or read source!) see how pointer expected used.
Comments
Post a Comment