|
Boost Users : |
From: Michael Bradley Jr (mbradley.jr_at_[hidden])
Date: 2008-06-02 11:11:23
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net