Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用QtConcurrent::run with重载函数_C++_Multithreading_Qt_Qtconcurrent - Fatal编程技术网

C++ 如何使用QtConcurrent::run with重载函数

C++ 如何使用QtConcurrent::run with重载函数,c++,multithreading,qt,qtconcurrent,C++,Multithreading,Qt,Qtconcurrent,我目前正在尝试并行化我的代码,因此我使用了QtConcurrent::run,问题是,run不知道选择哪个函数 有没有一种方法可以将run与重载函数一起使用,或者我是否找到了某种解决方法?您可以通过静态\u强制转换指针来确保过程中没有歧义 void hello(QString name) { qDebug() << "Hello" << name << "from" << QThread::currentThread(); } void

我目前正在尝试并行化我的代码,因此我使用了
QtConcurrent::run
,问题是,run不知道选择哪个函数


有没有一种方法可以将run与重载函数一起使用,或者我是否找到了某种解决方法?

您可以通过
静态\u强制转换
指针来确保过程中没有歧义

void hello(QString name)
{
    qDebug() << "Hello" << name << "from" << QThread::currentThread();
}

void hello(int age)
{
    qDebug() << "Hello" << age << "from" << QThread::currentThread();
}

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QFuture<void> f1 = run(static_cast<void(*)(QString)>(hello), QString("Alice"));
    QFuture<void> f2 = run(static_cast<void(*)(int)>(hello), 42);
    f1.waitForFinished();
    f2.waitForFinished();
}
void hello(QString名称)
{

qDebug()好的,这对像void hello(QString name,int age){..}和void hello(QString name){..}这样的重载也有效吗?好的,我自己想出来了,只需要使用函数前面的名称空间,而不是调用它的静态成员