简体   繁体   中英

Converting member function pointer to string

I have a class which consists of a function. I just need to call this function periodically. One timer callback api is there which is of the form mentioned below:

Timer(&obj,&Class::Func,Time) 

So if we attach the member function to this api, it will be called periodically.

There is a wrapper for this api which accepts arguments as string. So I need to pass every argument as string and do the necessary parsing and call the actual api.

So I want to first convert the object address and member function address to string and use it in my project. Can anyone help me by giving sample code to do this.

You cannot convert a member function to string and then use it at all.

There is a few way to convert a type or an expression to a string, like typeid , but it works only in this way, not in the opposite.

There is just no native way in C++ to convert a string to a member function address. However, you can make an associative container (like a std::map ) associating strings to member function pointers, and use it for wrapping and unwrapping.

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