dimanche 2 octobre 2016

Why is this unresolved overloaded function type error?

While compiling I am getting error

#include<iostream>
#include<thread>
#include<vector>
using namespace std;

int a=100;

void div()
{
        if(a!=0) int div1 = 100/a;
}

void assign()
{
        a=0;
}

int main()
{
        vector<thread> Threads;

        for(int i=0;i<100;i++)
        {
                Threads.push_back(thread(div));
                Threads.push_back(thread(assign));
        }
}

g++ div.cpp -std=c++11 -pthread

div.cpp: In function ‘int main()’:
div.cpp:24:31: error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>)’
   Threads.push_back(thread(div));
                               ^
In file included from div.cpp:2:0:
/usr/include/c++/5/thread:133:7: note: candidate: template<class _Callable, class ... _Args> std::thread::thread(_Callable&&, _Args&& ...)
       thread(_Callable&& __f, _Args&&... __args)
       ^
/usr/include/c++/5/thread:133:7: note:   template argument deduction/substitution failed:
div.cpp:24:31: note:   couldn't deduce template parameter ‘_Callable’
   Threads.push_back(thread(div));
                               ^
In file included from div.cpp:2:0:
/usr/include/c++/5/thread:128:5: note: candidate: std::thread::thread(std::thread&&)
     thread(thread&& __t) noexcept
     ^
/usr/include/c++/5/thread:128:5: note:   no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::thread&&’
/usr/include/c++/5/thread:122:5: note: candidate: std::thread::thread()
     thread() noexcept = default;
     ^
/usr/include/c++/5/thread:122:5: note:   candidate expects 0 arguments, 1 provided

I am not able to understand what is the problem here?

Aucun commentaire:

Enregistrer un commentaire