returning a multidimensional array with explicit return type in c++ -
i have class has member defined as:
float u[2][2];
now have accessor function , return reference array. so, have like:
const float & [2][2] mat() const { return u; }
is there way return using kind o syntax rather pointer syntax (i think makes things more explicit).
it's awkward, but:
const float (&mat() const)[2][2] { return u; }
using typedef or decltype
might better, eg:
const decltype(u) &mat() const { return u; }
or:
using mat22 = float[2][2]; const mat22 &mat() const { return u; }
(this latter 1 suggested daniel h. in comments).
or, in c++14, just:
const auto &mat() const { return u; }
Comments
Post a Comment