Boost logo

Boost Users :

From: Rupert Bruce (rupert_at_[hidden])
Date: 2008-06-02 10:41:37


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Bradley Jr wrote:
> Hi,
>
> i'm facing this problem may be someone on the list do have an elegant solution
>
This is really not a boost-related problem; this is basic C++.
>
> class A;
> class B;
>
> class C {
> int operator () (A*,B*)
> };
Try making class C look more like this:

class C
    {
    int operator()();

    A aInstance;
    B bInstance;
    };
You can then modify the operator() function to use aInstance and
bInstance instead of using parameters to pass them in.
>
> typedef int (*foobar)(A*,B*);
> void do_something(foobar cb);
Just a suggestion - eliminate all typedef statements from your code
until you really understand what your code is doing. Typedefs are merely
aliases that will add to your confusion.

>
> C obj;
> do_something(obj); *ERROR*
Yes, this is an error:
   - 'obj' is an instance of C that knows absolutely nothing about A or B
   - 'do_something()' is a function that expects a function pointer
(with pointer-to-A and pointer-to-B as its parameters) and knows nothing
about C

>
> 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.
There is no class B member function mentioned anywhere in your sample...

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFIRAah/X5Z5iyVCbERAhaBAJ0dMRBgIGpdsE1gO3WgK7VJ2grAFwCfUA0A
4kCYj9hx6uTEu/xn7Ex2rOc=
=8Aik
-----END PGP SIGNATURE-----


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