简体   繁体   中英

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:

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> . Invoke it explicitly as qMakePair<void (*)( ... ), int>( aaa::ccc, 0 ) or reinterpret_cast aaa::ccc to the desired function pointer type.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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