C++17 Template argument deduction failed

There are 2 issues with template argument deduction here. The std::function parameter can’t be deduced from the lambda argument, and deduction only works for parameter packs when they are trailing.

To fix this, you can change the order of the arguments to the constructor, like this:

Timer(std::function<void(Args...)> func, std::chrono::milliseconds step, Args&&... args)
 // ...                                                              //  ^^^^^^^^^ trailing 

and add a deduction guide

template<typename Func, typename ...Args>
Timer(Func, std::chrono::milliseconds, Args&&...) -> Timer<Args...>;

Here’s a demo.

Note the warning, your member initializer list is not in the same order as the member declarations.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top