首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >带有std::C2248的MVSE12中出现错误线程

带有std::C2248的MVSE12中出现错误线程
EN

Stack Overflow用户
提问于 2016-06-13 18:07:34
回答 2查看 195关注 0票数 0

大家晚上好!

我正在尝试用Microsoft Visual Studio Express 2012在C++中编写多线程应用程序。

我们的想法是,"main“函数调用一个线程,该线程将”永远“运行,任务是更新对象。

这是主要的:

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <thread>
#include <iostream>//debug only
#include <fstream> //debug only
#include "dataCollectorFTL.h"


int _tmain(int argc, _TCHAR* argv[])
{

    dataCollectorFTL dataCollector1;

    //Launch thread which will run forever and get the data flows
    dataCollector1.runDataCollector();


    while(true){
        //application running    
    }

    return 0;
} 

这是类的".h“

#ifndef DATACOLLECTORFTL_H_INCLUDED
#define DATACOLLECTORFTL_H_INCLUDED


#include <thread>

class dataCollectorFTL {

public:

    void runDataCollector();

    void getData(); 


    //constructor, destructor
    dataCollectorFTL();
    ~dataCollectorFTL();

private:
    HANDLE hProcess;
    std::thread dataCollectorThread;

};

#endif // DATACOLLECTORFTL_H_INCLUDED

最后是".cpp“

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <thread>
#include "dataCollectorFTL.h"


void dataCollectorFTL::runDataCollector(){

    //lauch a non-local thread
    dataCollectorThread = std::thread(&dataCollectorFTL::getData, this);
}


void dataCollectorFTL::getData(){
    //some stuff    

}

dataCollectorFTL::dataCollectorFTL(){
    //some stuff
}

dataCollectorFTL::~dataCollectorFTL(){

    dataCollectorThread.join();
}

问题是,当我运行它时,它给了我这两个错误:

错误1错误运算符:'std::thread::operator =‘C2248:无法访问在类'std::thread’c:\users\damien\documents\visual studio 2012\projects\recherche\recherche\datacollectorftl.h 233 1 Recherche中声明的私有成员

错误4错误C2248:‘std::thread::thread’:无法访问在类'std::thread‘c:\users\damien\documents\visual studio 2012\projects\recherche\recherche\datacollectorftl.h 233 1 Recherche中声明的私有成员

为了节省时间,我可以告诉你:

包含在.h中的

  • 不会更改任何内容
  • runDataCollector方法的内容不会更改任何内容。即使它是空的,我仍然得到problem
  • std::thread dataCollectorThread可以是公共的或私有的,它不会改变任何东西

如果我不声明为该类的成员,程序就会崩溃,因为我没有在runDataCollector()中联接()线程。我不想加入它,has ()是一个while(true)函数,它从另一个软体获取数据。

非常感谢您花时间阅读这篇文章,并再次感谢您的帮助。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37786966

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档