简体   繁体   中英

Function Pointer typedef Error

i defined my Function pointer with a typedef like

typedef void (*ThreadFunc)( void *);

my Class member method looks like :

 void start( ThreadFunc f, vector<void *> &jobs)

in my main program i wrote a function like :

 ThreadFunc runner( void *job )
 {
  printf("->> %p\n", job);
 };

and want to run the member function so i tried:

r.start( runner, jobs);

the compiler says:

main.cc:27: Fehler: ungültige Umwandlung von »void (* (*)(void*))(void*)« in »void (*)(void*)«
main.cc:27: Fehler:   Argument 1 von »void Thread::start(void (*)(void*), std::vector<void*, std::allocator<void*> >&)« wird initialisiert

Hope someone could help me short :) greetz

需要声明runner返回void ,而不返回ThreadFunc以匹配start的签名。

ThreadFunc runner( void *job )

isn't actually a ThreadFunc , but a function returning a ThreadFunc . The compiler is telling you basically that.

It should work if you declare the function as

void runner( void *job )

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