【发布时间】:2017-05-19 11:13:21
【问题描述】:
我正在尝试理解 C++ 中的线程,但我不知道如何解决这个问题。
我想调用两个线程来运行名为“createS”的函数,但我得到了这个错误:
错误:非静态成员函数的使用无效
我已阅读有关此主题的其他问题,但我真的不明白如何使我的代码正常工作。
有人可以解释我做错了什么并尝试帮助我找到解决方案吗?
test_class.cpp
void test_class::generateS(){
map1=new multimap<double,vector<int>>;
map2=new multimap<double,vector<int>>;
thread thread_1( createS, 0, nCells/2, map1 );
thread thread_2( createS, nCells/2, nCells, map2);
thread_1.join();
thread_2.join();
}
void test_class::createS(int startP, int endP, Costs *mapPointer){
//i do some stuff
}
test_class.h
void createS(int start, int end, Costs *mapPointer);
void generateS();
【问题讨论】:
-
尝试将 CreateS() 类设为静态。
标签: c++ multithreading compiler-errors non-static