0

i wrote template function with 3 parameters, T - type of array, FUNC - function that return and get T as parameter, and N as size of array. I get compilation error telling pretty much nothing :"Failed to specialize function template".

template<typename T,T* (*FUNC)(T), int N>
void process(T array[])
{
    for (int i=0;i<N;i++)
    {
        array[i] = FUNC(array[i]);
    }
}

int main()
{
    double a[] = { 1, 2, 3, 4 };
    process<double, sin, 4>(a); 
    for (auto x : a)
        std::cout << x << " "; // 0.841471 0.909297 0.14112 -0.756802
}
1
  • Is sin your own function or a standard function? What is the exact error text? Commented Mar 14, 2019 at 19:56

1 Answer 1

2

sin does not match the second template parameter. Change the function declaration to

template<typename T, T (*FUNC)(T), int N>
//                ^^ T, not T*
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i wrote * as pointer function and didn't realised that i gave two asterisk. Thanks very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.