dimanche 24 avril 2016

Coudn't run code used std::async on GCC 5.3.0

I was practicing std::asyn function that introduced in c++11, I wrote a simple example

#include<future>
#include<iostream>

using namespace std;

void check()
{
    cout<<"some"<<endl;
}
 int main()
 {
    auto p=std::async(std::launch::async,check);
    p.get();
 }

Yes very simple to start off with and i am compiling it using GCC 5.3.0

g++ -std=c++11 practise.cpp -lpthread

and the error

practise.cpp: In function 'int main()':
practise.cpp:13:47: error: invalid use of incomplete type 'class std::future<int>'
     auto p=std::async(std::launch::async,chech);
                                               ^
In file included from practise.cpp:1:0:
C:/Program Files/mingw32/i686-w64-mingw32/include/c++/future:115:11: note: declaration of 'class std::future<int>'
     class future;
           ^

Am i missing anything? is the way i linked lpthread is ok? i am on windows 7.

Aucun commentaire:

Enregistrer un commentaire