
Hi, Nikolai N Fetissov wrote:
Making the member function that has that signature static helps solve the problem but then we do have undesirable side-effect since this operation should be instance based and not object-bases. May be someone can come out with a better approach?!
With such restriction I would go with making C a singleton (or pooled object - same idea) and doing something like:
class C { public: int DoStuff( A*, B* ); // or op() - doesn't matter static C& GetInstance( /*XXX*/ ); // or pointer private: // singleton stuff ... };
// extern "C" ? int CallbackFunc( A* a, B* b ) { return C::GetInstance( /*XXX*/ ).DoStuff( a, b ); }
do_something( CallbackFunc );
This is of course just one way of doing things and very much depends on the context. Generally, you got a subsystem boundary and need to figure out a clean interface.
Your approach is exactly what we don't want, since it makes it an object-based based solution rather than instance-based. We are using a functor (therefor the oprerator()) so that the solution remains instance-based. Like I've said we want to apply it to different instances of C with their own different and non-static member variables. C c1,c2,c3; Did google a bit and one possible solution was boost::function in combination with boost::bind. But I'm not familiar to that ;( Cheers Mike