简体   繁体   English

指向具有可变参数编号的函数的指针

[英]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.

相关问题 返回带有可变数量的参数的函数指针 - Return a function pointer, with variable number of arguments 在结构对象中存储指向具有可变数量参数的函数的指针 - Store pointer to function with variable number of arguments, in struct object C ++:函数指向具有可变数量参数的函数 - C++: Function pointer to functions with variable number of arguments 函数指针模板的参数数目 - Function pointer template number of arguments 函数指针中的参数个数不同 - Different number of arguments in function pointer lambda中的变量参数作为函数指针 - variable arguments in lambda as function pointer 这是编写接受带有可变数量参数的函数指针的函数模板的正确方法吗? - Is this the correct way to write a function template which accepts a function pointer with a variable number of arguments? 带有推导参数的模板函数指针数组变量 - Template function pointer array variable with deduced arguments 是否可以通过全局变量定义具有可变数量的参数的函数中的参数数量 - Is it possible to define the amount of arguments in a function with variable number of arguments by a global variable 指向具有任意数量参数的任何成员函数的函数指针 - function pointer to any member function with any number of arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM