c++ - Table pass by value -


this question has answer here:

is possible pass raw table function value? believe it's impossible, i'm looking official sources confirm that.


i know how pass table reference:

template<typename t, size_t n, size_t m> void first_example(t (&table_in_function)[n][m]) {   //...  }  //... int a[50][20]; //... first_example(a); 

or std::array, sad, i'm looking solution raw tables. simple idea, remove &, wrong. not looking like:

template<typename t, size_t n, size_t m> void third_example(t (&temp_ref)[n][m]) {   t local_table[n][m];   //...  } 

i accept solutions magic code , meta-programming.

it impossible declare function parameter of array type. in particular c++ standard (§8.3.5/5) specifies:

after determining type of each parameter, parameter of type “array of t” or “function returning t” adjusted “pointer t” or “pointer function returning t,” respectively.

so, if attempt create function taking parameter array type, parameter "adjusted" compiler become pointer instead.

likewise, when/if attempt pass array function, passed address of first element of array.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -