jeudi 23 juillet 2015

c++11 Passing shared_ptr as parameter in async call

I am converting my code to multi thread to performance enhancement.

I have vector of shared_ptr and an object of another class and I am passing a shared_ptr from vector and an object as parameter to function. I am calling it using std::async but it is giving me following error :

line from where I am making async call : required from here 
/usr/include/c++/4.8.2/functional1697.61: error: no type named 'type' 
in 'class std::result_of<void (*(std::shared_ptr<A>, B))
(const  std::shared_ptr<A>&, B&)>'typedef typename 
result_of<_Callable(_Args...)>::type result_type;

Here is code snippet :

void foo(std::vector<std::shared_ptr<A>>& a, B b){
    std::vector<std::future<void>> tasks;
    for(auto& sptr : a ){
        tasks.push_back(std::async(std::launch::async, foo1, a, b))
    }

 void foo1(const std::shared_ptr<A>& a, B& b ){
    //do some stuff
 }

Can you please help me. Thanks

Aucun commentaire:

Enregistrer un commentaire