[英]Pointer to a function with variable arguments number
I have declared: 我宣布:
class aaa {
public:
static std::queue<QPair<void (*)( ... ), int> > m_commands;
static int bbb();
static void ccc(...);
};
and in bbb() method I wrote: 在bbb()方法中我写道:
int aaa::bbb() {
m_commands.push( qMakePair( aaa::ccc, 0 ) );
}
but it complains about: 但它抱怨:
error C2664: 'void std::queue<_Ty>::push(QPair<T1,T2> &&)' : cannot convert parameter 1 from 'QPair<T1,T2>' to 'QPair<T1,T2> &&'
why? 为什么? When I had function like that: 当我有这样的功能时:
void reg( void ( *invoker )( ... ), int args ) {
m_commands.push( qMakePair( invoker, args ) );
}
I could easily send to the above function a static function this way: 我可以通过这种方式轻松地向上面的函数发送静态函数:
reg( aaa::ccc, 0 );
qMakePair( aaa::ccc, 0 )
is (presumably) returning a value of type QPair<void (*)(), int>
, since it doesn't know that you want a value of type QPair<void (*)( ... ), int>
. qMakePair( aaa::ccc, 0 )
(可能)返回QPair<void (*)(), int>
类型的值,因为它不知道你想要一个QPair<void (*)( ... ), int>
类型的值QPair<void (*)( ... ), int>
。 Invoke it explicitly as qMakePair<void (*)( ... ), int>( aaa::ccc, 0 )
or reinterpret_cast
aaa::ccc
to the desired function pointer type. 将其显式调用为qMakePair<void (*)( ... ), int>( aaa::ccc, 0 )
或reinterpret_cast
aaa::ccc
为所需的函数指针类型。
Not to mention that this is (almost certainly) illegal , as aaa::ccc
does not have the correct signature and cannot be invoked through the function pointer type you're using. 更不用说这(几乎可以肯定)是非法的 ,因为aaa::ccc
没有正确的签名,不能通过你正在使用的函数指针类型调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.