简体   繁体   English

如何将 void 转换为 typedef void(...)(float)

[英]How to convert void to typedef void(...)(float)

I have this on one class:我在一节课上有这个:

typedef void(*PERCENTAGE_CALLBACK)(float);

And I use it on functions like this one:我在这样的函数上使用它:

int API_GenerateLayerData(int layerIndex, QByteArray data, int dataSize, PERCENTAGE_CALLBACK callBack);

But the thing is that I can't pass a parameter with a void return type and accepts float as a parameter like this:但问题是我无法传递带有 void 返回类型的参数并接受 float 作为参数,如下所示:

void updateFormattingProcess(float value)
{
    emit ChangeCompose(int(value));
}

void someFunction()
{ 
    //It says cannot convert from 'void' to 'PERCENTAGE_CALLBACK'
    API_GenerateLayerData(1, data, count, updateFormattingProcess(x));
}

You are trying to call the function with updateFormattingProcess(x) and pass the result of that function call (which is void ) as a parameter of type void(*)(float) .您正在尝试使用updateFormattingProcess(x)调用该函数, updateFormattingProcess(x)该函数调用的结果(即void )作为void(*)(float)类型的参数传递。 Instead, just pass a pointer to it:相反,只需传递一个指向它的指针:

API_GenerateLayerData(1, data, count, &updateFormattingProcess);
//                                    ^ take the addresss of the function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM