C++ return std::pair<int *,int *>? -


#include <iostream> #include <string> #include <utility> using namespace std; string num1="123456789123456789"; std::pair<int*,int*> cpy(){     int  a[(num1.size()%9==0)? num1.size()/9 : num1.size()/9+1];     int  b[(num1.size()%9==0)? num1.size()/9 : num1.size()/9+1];    return make_pair(a,b); } int main(void){    return 0; } ------------------------------------------------------- //if style, can compiled std::pair<int*,int*> cpy(){ const int n=5; int  a[5]; int  b[5]; return make_pair(a,b); 

}

i writing program calculate big number such 19933231289234783278, need split number using 1 000 000 000 system

why can't return pair way?

you can't return pair way, because passing wrong types. in case, array doesn't decay pointer.

if change last line in function :

return make_pair(&a[0],&b[0]); 

it compile, still not work, returning pointers arrays, destroyed, once function cpy() ends.

by way, variable lenghts array not standard c++.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -