调用外部函数的类 [英] class calling an external function
本文介绍了调用外部函数的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下情况是否合理?
Is the following scenario plausible?
class MyClass
{
_ beginthreadex(NULL,0, function, 0,0,0);
}
int main ()
{
MyClass RunOldMain;
return;
}
void function(LPWSTR lpParam )
{
// function is plain 'C'
return;
}
如果是,那么需要什么声明?
If yes, then what declarations are required?
推荐答案
如果您的类实际上是一个类,这似乎是合理的.如果要在构造函数中启动线程:
It''d be plausible if your class was actually a class. If you want to start a thread in the constructor:
class MyClass
{
public:
MyClass()
{
void function( void * );
_ beginthreadex(NULL,0, function, 0,0,0);
}
}
会成功的只要声明了函数,就可以在_beginthreadex
调用中使用它的名称.您甚至可以在另一个翻译单元(源文件)中声明它.
请注意,除非您将第一个参数更改为void *
或使用小的包装程序为您进行强制转换,否则定义function
的代码将不会编译.
干杯,
灰
will do the trick. As long as the function is declared you can use it''s name in your _beginthreadex
call. You can even declare it in another translation unit (source file).
Note that the way you defined function
the code won''t compile unless you change the first parameter to be a void *
or use a small wrapper to do the cast for you.
Cheers,
Ash
这篇关于调用外部函数的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文