2016-11-23 99 views

回答

3

你可以只static_cast指针以确保在这一过程中

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(); 
} 

或可选择地获得一个指向正确的没有歧义。

+0

好吧,这是否适用于像以下这样的过载:void hello(QString name,int age){..}和void hello(QString name){..}呢? –

+0

确定我自己想出来,只需要在函数前面使用名称空间,而不是静态成员,它调用它 –