0

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

selecsosi
  • 161
  • 1
  • 3
  • 11

1 Answers1

1

Try

template <class NumType, size_t N>
void F(NumType (&array)[N]);
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • Thank you, this worked. I will checkmark it when the system allows me to. This is perfect for variable size arrays. In my case, I could require a fixed size array. Using your answer, I specialized mine to length three arrays template void F(NumType (&array)[3]); – selecsosi Feb 18 '14 at 22:45