未调用数组的函数专用化

Function specialization for arrays not being called

本文关键字:专用 函数 调用 数组      更新时间:2023-10-16

我有一个函数,它在其参数上模板化:

template <class Vector>
void F(Vector& vec);

我想为数字数组添加此函数的专用化。 我的尝试如下所示:

template <class NumType>
void F(NumType array[]);

我在调用代码中的专用函数时遇到困难。 见下文:

void main()
{
  double a[] = {0.0, 1.0};
  F(a); // This calls the Vector version of the function,
        // with Vector = double [3], in my specific case.
}

如果它有帮助,我事先知道该函数需要一个长度为 3 的数组才能正常工作。

如何修复我的专用函数声明,以便调用函数的 NumType 数组版本?

谢谢

尝试

template <class NumType, size_t N>
void F(NumType (&array)[N]);