Boost logo

Boost Users :

From: wang wenhua (wangwenhua01_at_[hidden])
Date: 2008-06-04 01:28:28


void do_something(foobar cb); // this function accepts argument
which is a point of function
do_something(obj); // but obj is a function.
i think we should do it like tihs

class A {
};
class B {
};
class C {
public:
int operator () (A*,B*){
cout<<"yes"<<endl;
return 1;
}
};

typedef int (*foobar)(A*, B*);
void do_something(foobar cb) {
cout<<"something"<<endl;
}

A *aPtr=new A;
B *bPtr=new B;
C obj;
foobar fooPtr=obj.operator(); //there is still error like this
 "argument of type `int (C::)(A*, B*)' does not match `int (*)(A*, B*)'"
  i can't correct it. but it may be helpful to you.

2008/6/2, Michael Bradley Jr <mbradley.jr_at_[hidden]>:
>
> Hi,
>
> i'm facing this problem may be someone on the list do have an elegant
> solution
>
>
> class A;
> class B;
>
> class C {
> int operator () (A*,B*)
> };
>
> typedef int (*foobar)(A*,B*);
> void do_something(foobar cb);
>
> C obj;
> do_something(obj); *ERROR*
>
> did try boost::function<int(A*,B*)> ftor = obj;
> do_something(ftor); *ERROR*
>
> compiler generates in both cases the following error messages
> cannot convert parameter 2 from 'boost::function<Signature>' to 'int
> (__cdecl
> *)(A *,B *)'
>
> with
> 1> [
> 1> Signature=int (A *, B *)
> 1> ]
> 1> No user-defined-conversion operator available that can perform
> this
> conversion, or the operator cannot be called
>
>
> I can't make the corresponding class B member function static due to
> side-effects.
> Any clue how to get rid of this?
>
> Thanks in advance
> Mike
>
>
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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