问题是以下代码:
#include <pthread.h>voID *draw(voID *pt) { // ...}voID *input(voID *pt) { // ....}voID Game::create_threads(voID) { pthread_t draw_t,input_t; pthread_create(&draw_t,NulL,&Game::draw,NulL); // Error pthread_create(&input_t,NulL); // Error // ...}
但是Xcode给了我错误:“没有匹配函数调用’pthread_create’”.我不知道’因为我已经包含了pthread.h.
怎么了?
谢谢!
解决方法 正如Ken所说,作为线程回调传递的函数必须是(voID *)(*)(voID *)类型函数.您仍然可以将此函数作为类函数包含在内,但必须将其声明为static.您可能需要为每种线程类型(例如绘图)使用不同的一种.
例如:
class Game { protected: voID draw(voID); static voID* game_draw_thread_callback(voID*);};// and in your .cpp file...voID Game::create_threads(voID) { // pass the Game instance as the thread callback's user data pthread_create(&draw_t,Game::game_draw_thread_callback,this);}static voID* Game::game_draw_thread_callback(voID *game_ptr) { // I'm a C programmer,sorry for the C cast. Game * game = (Game*)game_ptr; // run the method that does the actual drawing,// but Now,you're in a thread! game->draw();}总结
以上是内存溢出为你收集整理的c – 没有匹配函数调用’pthread_create’全部内容,希望文章能够帮你解决c – 没有匹配函数调用’pthread_create’所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)