How to pass a VLA to a function template?

后端 未结 6 1893
温柔的废话
温柔的废话 2020-12-12 05:00

I have the following code which could not be complied.

using namespace std;
void f(int);
template
void array_ini_1d(T1 (&x)[         


        
6条回答
  •  猫巷女王i
    2020-12-12 05:43

    Template parameters must be resolved at compile-time.

    There is no way that a function template with parameter size_t N can match any sort of array or other container whose size comes from a run-time input.

    You will need to provide another version of the array_1d_ini which does not have the size as a template parameter.

提交回复
热议问题