How to pass a typedef function as a parameter in C/C++ -


i've been looking around online awhile , haven't found issue. using class has thing defined:

typedef bool progresscallback(double progress); 

there function uses so:

// documentation says call progress_callback() // during write progress parameter = percentage complete void writetofile(char* filename, progresscallback* progress_callback) 

how supposed call function?? it's typedef syntax that's throwing me off, because it's not difficult pass function parameter. here's tried though:

// apparently can't "progress callback mycallback{}" // since gives me "function type may not come typedef" error bool mycallbackfunction(double progress){     return true; }  void otherfunction(){      // can't assign. "a value type of bool (*)(double progress)" cannot     // used initalize entity of type progresscallback*" error.     progresscallback* myfunction = mycallbackfunction;     writetofile("test.txt", myfunction); } 

obviously know doing incorrectly. closest i've gotten. have absolutely no idea how supposed pass argument writetofile().

any appreciated!

use

typedef bool (*progresscallback)(double progress); 

to define progresscallback.

then, can use

progresscallback myfunction = mycallbackfunction; writetofile("test.txt", myfunction); 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -