Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么我会得到一个“a”;在‘;struct std::_Bind_simple<;Fctor()>’&引用;错误_C++_Multithreading_C++11 - Fatal编程技术网

C++ 为什么我会得到一个“a”;在‘;struct std::_Bind_simple<;Fctor()>’&引用;错误

C++ 为什么我会得到一个“a”;在‘;struct std::_Bind_simple<;Fctor()>’&引用;错误,c++,multithreading,c++11,C++,Multithreading,C++11,我刚刚开始在C++11中使用多线程,我偶然发现了一个我不理解的错误 这是我的multi1.cpp文件: #include <iostream> #include <thread> using namespace std; class Fctor { public: void operator() (string msg) { std :: cout << "From Fctor: "<< msg << std

我刚刚开始在
C++11
中使用多线程,我偶然发现了一个我不理解的错误

这是我的
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;
}
这会导致编译时出现错误,并打印:

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’ in ‘class 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’ in ‘class std::result_of<Fctor()>’
         _M_invoke(_Index_tuple<_Indices...>)
在/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/thread:39:0中包含的文件中,
来自multi1.cpp:2:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/functional:在“struct std::_Bind_simple”的实例化中:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/thread:137:47:std::thread::thread(_-Callable&&,_-Args&&&…[with _-Callable=Fctor&;_-Args={}]中的必填项
multi1.cpp:15:19:从此处开始需要
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/functional:1665:61:错误:在“类std::result_of”中没有名为“type”的类型
typedef typename result_of::type result_type;
^
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/functional:1695:9:错误:在“类std::result_of”中没有名为“type”的类型
_M_invoke(_Index_tuple)
我无法理解编译器想告诉我什么。当我浏览博倩在YouTube上的视频时,我试图了解事情是如何运作的


提前感谢各位。

在UbuntuI上使用GCC4.9.2编译得很好。我在Windows上更新了我的
PATH
环境变量,指向
GCC
安装的bin文件夹后,我在
cmd
上尝试了它,它编译得很好。我的
cygwin
安装可能有问题,尽管我不得不这么做记住给它
-pthread
选项。你确定这是你的实际代码吗?所有推断出的类型都是完全错误的。这些错误对应于
Fctor f;标准:螺纹t1(f)代码正常,可以在任何地方编译。关于Fctor()的parentshis表明代码是不同的,因为那里不需要它们。
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’ in ‘class 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’ in ‘class std::result_of<Fctor()>’
         _M_invoke(_Index_tuple<_Indices...>)