C++ C++;std::当前类中的线程传递成员函数

C++ C++;std::当前类中的线程传递成员函数,c++,multithreading,C++,Multithreading,我试图通过一个成员函数进行线程调用。问题是我在同一类的另一个成员函数中进行调用。我的意思是: class A { void foo(int a); void bar() { int k = 2; thread t(&A::foo, this, k); } } 我还试图将this作为参考传递:this或std::ref(this),但没有成功。我到底犯了什么错 编辑:下面是给出错误的实际代码 class SUBTHREAD { public

我试图通过一个成员函数进行线程调用。问题是我在同一类的另一个成员函数中进行调用。我的意思是:

class A {
   void foo(int a);

   void bar() {
       int k = 2;
       thread t(&A::foo, this, k);
   }
}
我还试图将
this
作为参考传递:
this
std::ref(this)
,但没有成功。我到底犯了什么错

编辑:下面是给出错误的实际代码

class SUBTHREAD {
public:
    SUBTHREAD(const SOCKET client, const int ID, MAINTHREAD *Server);

    void handleQFStreaming(const vector<string> &splitMessage);
    void handleIncoming(const string &message, const int &length);
    void run();

private:
    MAINTHREAD *Server;
    SOCKET client;
    vector<thread> QFSThreads;
    int ID;

};

void SUBTHREAD::handleQFStreaming(const vector<string> &splitMessage) {
     ...
}

void SUBTHREAD::handleIncoming(const string &message, const int &length) {
     ...
     QFSThreads.push_back(thread(&SUBTHREAD::handleQFStreaming, this, splitMessage));
     ...
}
类子线程{
公众:
子线程(constsocketclient,constintid,MAINTHREAD*Server);
void handleQFStreaming(const vector和splitMessage);
void handleIncoming(常量字符串和消息、常量int和长度);
无效运行();
私人:
主线程*服务器;
套接字客户端;
向量qfst线程;
int-ID;
};
void子线程::handleQFStreaming(const vector和splitMessage){
...
}
void子线程::handleIncoming(常量字符串和消息,常量int和长度){
...
push_back(线程(&SUBTHREAD::handleqfstreating,this,splitMessage));
...
}
编辑:我得到的全部错误是:

1>------ Build started: Project: BankServer, Configuration: Debug Win32 ------
1>  bserver.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(593): error C2280: 'std::thread::thread(const std::thread &)' : attempting to reference a deleted function
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\thread(70) : see declaration of 'std::thread::thread'
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(592) : while compiling class template member function 'void std::allocator<_Ty>::construct(_Ty *,const _Ty &)'
1>          with
1>          [
1>              _Ty=std::thread
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(723) : see reference to function template instantiation 'void std::allocator<_Ty>::construct(_Ty *,const _Ty &)' being compiled
1>          with
1>          [
1>              _Ty=std::thread
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\type_traits(572) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=std::thread
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\vector(650) : see reference to class template instantiation 'std::is_empty<_Alloc>' being compiled
1>          with
1>          [
1>              _Alloc=std::allocator<std::thread>
1>          ]
1>          e:\programming\workspace\visual studio 2013\projects\bankserver\bankserver\bserver.h(63) : see reference to class template instantiation 'std::vector<std::thread,std::allocator<_Ty>>' being compiled
1>          with
1>          [
1>              _Ty=std::thread
1>          ]
1>  Generating Code...
1>  Compiling...
1>  main.cpp
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
1>----构建已启动:项目:BankServer,配置:调试Win32------
1> bserver.cpp
1> c:\ProgramFiles(x86)\microsoft visual studio 12.0\vc\include\xmemory0(593):错误C2280:“std::thread::thread(const std::thread&”):试图引用已删除的函数
1> c:\ProgramFiles(x86)\microsoft visual studio 12.0\vc\include\thread(70):请参阅“std::thread::thread”的声明
1> c:\ProgramFiles(x86)\microsoft visual studio 12.0\vc\include\xmemory0(592):编译类模板成员函数“void std::allocator::construct(_Ty*,const _Ty&)”时
1> 与
1>          [
1> _Ty=std::thread
1>          ]
1> c:\ProgramFiles(x86)\microsoft visual studio 12.0\vc\include\xmemory0(723):请参阅正在编译的函数模板实例化“void std::allocator::construct(_Ty*,const _Ty&)”的参考
1> 与
1>          [
1> _Ty=std::thread
1>          ]
1> c:\ProgramFiles(x86)\microsoft visual studio 12.0\vc\include\type_traits(572):请参阅正在编译的类模板实例化“std::allocator”的参考
1> 与
1>          [
1> _Ty=std::thread
1>          ]
1> c:\ProgramFiles(x86)\microsoft visual studio 12.0\vc\include\vector(650):请参阅正在编译的类模板实例化“std::is_empty”的参考
1> 与
1>          [
1> _Alloc=std::分配器
1>          ]
1> e:\programming\workspace\visual studio 2013\projects\bankserver\bankserver\bserver.h(63):请参阅正在编译的类模板实例化“std::vector”的参考
1> 与
1>          [
1> _Ty=std::thread
1>          ]
1> 正在生成代码。。。
1> 编译。。。
1> main.cpp
1> 正在生成代码。。。
======生成:0成功,1失败,0最新,0跳过==========
问题是

vector<thread> QFSThreads;
向量QFSThreads;
不允许复制std::线程


@参见

注释不用于扩展讨论;此对话已被删除。但是
std::thread
s可以移动:但我不复制它,我只是声明它