문제

I have a function which is templated on its argument:

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

I want to add a specialization of this function for numeric arrays. My attempt looks like this:

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

I am having difficulty in calling the specialized function in the code. See below:

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.
}

If it helps, I do know beforehand that the function needs a length 3 array to work properly.

How do I fix my specialized function declaration so the NumType array version of the function is called?

Thanks

도움이 되었습니까?

해결책

Try

template <class NumType, size_t N>
void F(NumType (&array)[N]);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top