为什么线程过程应该是静态的或成员函数 [英] why does thread procedure should be static or member function
本文介绍了为什么线程过程应该是静态的或成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么线程过程应该是静态的或成员函数? 有任何正当理由吗?
why does thread procedure should be static or member function? any valid reason?
推荐答案
非静态成员变量具有由编译器内部传递的隐式this
参数.
Non-static member variables have an implicit this
parameter passed by the compiler internally.
你有
ClassInQuestion {
void threadFunc( int );
}
然后编译器在内部创建一个函数
and the compiler internally creates a function
void ClassInQuestion_threadFunc( ClassInQuestion* thisObject, int );
因此,除非线程过程接受具有第一个参数为ClassInQuestion*
类型的函数的指针t,否则它将与预期的函数签名不匹配.
So unless the thread procedure accepts a pointer t a function that has a first parameter of type ClassInQuestion*
it will not match the expected function signature.
这篇关于为什么线程过程应该是静态的或成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文