lundi 28 septembre 2020

Got undefined reference calling template function passing function pointer as a argument [duplicate]

I am write thread pooling code but when i compiled its show ' undefined reference to `std::future<decltype ({parm#1}({parm#2}...))> ThreadPool::enqueue<void* (&)(void*), void*>(void* (&)(void*), void*&&)'' as a error.

I mentioned function declaration, definition, and calling below.

Declaration:-

template<typename F, typename...Args> auto enqueue(F&& f, Args&&... args) -> std::future<decltype(f(args...))>;

Definition:-

template<typename F, typename...Args>
auto ThreadPool::enqueue(F&& f, Args&&... args) -> std::future<decltype(f(args...))>
 {
std::function<decltype(f(args...))() > func = std::bind(std::forward<F>(f), std::forward<Args>(args)...);
auto task_ptr = std::make_shared < std::packaged_task<decltype(f(args...))()>>(func);
std::function<void() > wrapper_func = [task_ptr]()
{
  (*task_ptr)();
};
mTasks.emplace(wrapper_func);
// debugLog->PrintLog("Inside Thread pool enqueue, function insert new function call\n");
cv.notify_one();
return task_ptr->get_future();

}

Calling:-

thread_pool->enqueue(fnReceive,(void *) sThreadStruct1);

I got the above error at calling and fnReceive is used by the thread pool to process.

Kindly help me to resolve this error.

Thanks and Regards, Vivek Singh

Aucun commentaire:

Enregistrer un commentaire