1

I'm writing a sample code to learn the asynchronos function with std::async.

My code it's very simple:

#include <iostream>
#include <future>

void error(char *msg)
{
    std::cout << msg;
}


int main(int argc, char * argv[])
{
    std::future<void> asyncr = std::async(errore,"start async");

    std::cout << "finish";
}

i think this is all correct, but my VisualStudio with VisualGDB throw an error in "asyncr":

[Clang IntelliSense] Error: implicit instantiation of undefined template 'std::future'

I lost several hours, and i want to find a solution.

I will be very grateful to those who will help me

  • 1
    `std::future` is a C++11 feature, so you need to check whether the compiler supports it and if you are passing the correct flags to enabled C++11 (if required) – UnholySheep Apr 30 '17 at 11:53
  • CFLAG: -ggdb -ffunction-sections CXXFLAG: -std=gnu++14 -ggdb -ffunction-sections -O0 -lpthread – Manuele Perrone Apr 30 '17 at 12:06
  • 1
    This isn't the problem, but to ensure that text is displayed on the console it should end with a newline character (`'\n'`): `std::cout << "finish\n";`. For the call to `std::async` you can either add the newline to the text that you pass in (`"start async\n"`) or you can add it explicitly in the output line: `std::cout << msg << '\n';`. – Pete Becker Apr 30 '17 at 12:11
  • 1
    is not a problem how the text is displayed @PeteBecker – Manuele Perrone May 01 '17 at 08:07
  • 1
    @ManuelePerrone Could you add a full error message? Because without typos all works. – malchemist May 02 '17 at 15:29
  • @ManuelePerrone How did you solve the problem? – royalTS Feb 20 '18 at 08:26

0 Answers0