"error I am just starting out with multithreading in ...">

Why do I get the message "In creating an instance" struct std :: _ Bind_simple <Fctor ()> "error

I am just starting out with multithreading in C++ 11and I stumbled upon an error that I don't understand.

This is my file multi1.cpp:

#include <iostream>
#include <thread>

using namespace std;
class Fctor {
public:
    void operator() (string msg) {
        std :: cout  << "From Fctor: "<< msg << std :: endl;
    }
};

int main()
{
    string s = "Hello world";
    std::thread t1((Fctor()),s);

    t1.join();
    return 0;
}

Now I am trying to run this file in the environment cygwinusing the following command:

$ g++ -std=c++11 multi1.cpp -o output

This results in a compilation error that prints:

In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/thread:39:0,
                 from multi1.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/functional: In instantiation of ‘struct std::_Bind_simple<Fctor()>’:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/thread:137:47:   required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = Fctor&; _Args = {}]’
multi1.cpp:15:19:   required from here
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/functional:1665:61: error: no type named ‘type’ inclass std::result_of<Fctor()>’
       typedef typename result_of<_Callable(_Args...)>::type result_type;
                                                             ^
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/functional:1695:9: error: no type named ‘type’ inclass std::result_of<Fctor()>’
         _M_invoke(_Index_tuple<_Indices...>)

I can’t understand what the compiler is trying to tell me. I am trying to understand how everything works when I look at the tutorial on C ++ multithreading on YouTube Bo Qian.

Thanks in advance guys.

+4
source share

Source: https://habr.com/ru/post/1607741/


All Articles