C++: static function wrapper that routes to member function?

前端 未结 4 414
北荒
北荒 2021-01-14 05:45

I\'ve tried all sorts of design approaches to solve this problem, but I just can\'t seem to get it right.

I need to expose some static functions to use as callback f

4条回答
  •  死守一世寂寞
    2021-01-14 06:44

    It's possible. Perhaps there's a problem on how you're initializing the concrete implementation?

    In fact, I remember one library that does something very similar to this. You might find it usefull to take a look at libxml++ source code. It's built on top of libxml, which is a C library.

    libxml++ uses a struct of static functions to handle the callbacks. For customization, the design allows the user to provide (through virtual functions) his/her own implementations to which the callbacks are then forwarded. I guess this is pretty much your situation.

提交回复
热议问题