Error binding reference to array passed to function (c++) -
i'm using mingw64
eclipse
, language c++
stated above.
i have following code:
double * my_function (my_class i1, my_class i2, double return_vector[3]) { double test[3]; double (&rtest)[3]=test; double (&description_vector)[3] = return_vector; // more code return (description_vector); }
binding rtest test works fine, here compiler tells me warning: unused variable
, expected, it's not used anywhere in code wanted find out if works in principle.
however binding description_vector
return_vector
results in following error:
error: invalid initialization of reference of type 'double (&)[3]' expression of type 'double*'
why? why binding rtest test legal not binding of description_vector
return_vector
?
so may ask "but why binding reference description_vector
return_vector
? use return_vector
in return statement - it's same after all."
i want confer information reader of code (basically me when i'll @ in future). way see have pass vector function purpose of returning it's calculation. see description_vector
alias return_vector
, name of description_vector
can see supposed hold.
when pass array function decays pointer first element , can't bind reference array. should either pass reference array parameter or make life easier using vectors (and iterators).
Comments
Post a Comment