Boost logo

Boost Users :

From: Nikolai N Fetissov (nikolai-boost_at_[hidden])
Date: 2008-06-02 12:04:06

>>> 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 ;(

boost::bind is very powerful but that won't work against
legacy code taking plain function pointer either.
My impression is that you are going the wrong way about this.
Functors "look" like functions, but underlying mechanism
is different. It's not like having operator() makes a class
magically "derived" from a function pointer.
Unless you control that legacy source code you will need
a free function here to take address of.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at