Returning a pointer to array of fixed sized arrays C++ -


i tried searching everywhere, because such perplexing question, wasn't able find looking for. trying create function/method don't know how specify return type, should be:

double(*)[3] 

i want able use query one:

double r[3][3]; query ( &output, r ); 

but instead of r[3][3], have vector std::vector<double> r_vect (9); , this:

query ( &output, reinterpret_cast<double(*)[3]> (r_vect.data()) ); 

which mess, wanted implement function make readable, say:

returntype cast ( const std::vector<double>& r_vect ) {   return reinterpret_cast<double(*)[3]> (r_vect.data()); } 

but can't specify return type. used typedef, , works:

typedef double desiredcast[3]; desiredcast* cast ( ... ) { ... } 

but still curious how without typedefs.

you should typedef complicated return types these, rather require reader untangle them. (or redesign don't have complicated types!)

but can follow pattern. declare variable of type do

double (*var)[3]; 

and make function put usual decoration in usual place next name, despite horrible seems. e.g. int argument named z:

double (*func(int z))[3] {     // ... } 

incidentally, cdecl you, once learn language.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -