472,990 Members | 3,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,990 software developers and data experts.

callback and boost:function

Guys,

Is there anyway in C++ to setup a callback for a member function that
takes two arguments
I am trying to use boost::function but that only works with
std::bind1st that does only take one parameter.

My function I want to call back looks like this:
struct X {
double f_cos(double x , void * p);
};

Regards
Lars

Jan 11 '06 #1
8 10938
To get ride of the void* I would like to use the boost::lambda library
so I can do _1, _2 as arguments.
But this does also not seems to work with more than one argument.
Lars

Jan 11 '06 #2
I will have a look at the sigc++ library for now as a workaround until
someone comes up with a better solution.
http://libsigc.sourceforge.net
Lars

Jan 11 '06 #3
On 11 Jan 2006 00:49:43 -0800 in comp.lang.c++, "Lars Schouw"
<sc******@yahoo.com> wrote,
Is there anyway in C++ to setup a callback for a member function that
takes two arguments


Why are you trying to setup a callback as a member function?

I suspect you need to read topic "[33.2] How do I pass a
pointer-to-member-function to a signal handler, X event callback,
system call that starts a thread/task, etc?" in Marshall Cline's C++
FAQ. It is always good to check the FAQ before posting. You can
get the FAQ at:
http://www.parashift.com/c++-faq-lite/
Jan 12 '06 #4
David

I already had a look at the FAQ last time I looked into this problem
one year ago.

The FAQ does not describe how to extended it with generic lambda code.
This is an extra plus I would like to be able to have if possible.

Last time I looked at it I got it up and running as described in the
FAQ I will see if I can get it running again.
boost::function is more elegant so it would be nice if I would be able
to make that work somehow.
I am stuck in how to do that at the moment.

Lars

Jan 12 '06 #5
Lars Schouw wrote:
Guys,

Is there anyway in C++ to setup a callback for a member function that
takes two arguments
I am trying to use boost::function but that only works with
std::bind1st that does only take one parameter.
I don't know how you came to this conclusion, but this is false.
My function I want to call back looks like this:
struct X {
double f_cos(double x , void * p);
};


Assuming you want to supply an X pointer and both args you could:

typedef boost::function< double, X*, double, void* > tFnc;

tFnc lFnc = boost::bind( &X::f_cos, _1, _2, _3 );

then call via

lFnc( &x, somedbl, someptr );

Jeff Flinn
Jan 12 '06 #6
typedef boost::function< double, X*, double, void* > tFnc;

give me:
c:\sletmig\templatedcallback\test.cpp(18) : error C2977:
'boost::function' : too many template arguments
c:\dev\boost\boost_1_33_1\boost\function\function_ base.hpp(92)
: see declaration of 'boost::function'

when I compile.... any idea?

Lars

Jan 13 '06 #7
On 12 Jan 2006 16:46:45 -0800
"Lars Schouw" <sc******@yahoo.com> wrote:
typedef boost::function< double, X*, double, void* > tFnc;

give me:
c:\sletmig\templatedcallback\test.cpp(18) : error C2977:
'boost::function' : too many template arguments
c:\dev\boost\boost_1_33_1\boost\function\function_ base.hpp(92)
: see declaration of 'boost::function'

when I compile.... any idea?

Lars


That's because it's a mix between two notations. Thus you write either :

typedef boost::function< double (X*, double, void*) > tFnc;

but it does not work with all compiler (look at the boost::function
websites to know which compilers ...), or you use :

typedef boost::function3<double, X*, double, void*> tFct;

Now, if you want to store the function just use :

tFct fct = &X::f_cos; // No need to use bind !

However, if you want to use a zero argument function as a callback,
use :

boost::function<double> fct = boost::bind(&X::f_cox, x, somedbl,
someptr);

Then call :

double d = fct();

Also, you can bind part of the arguments using _1, _2, ... and the
correct function definition.

Pierre

--
You will have good luck and overcome many hardships.
Jan 13 '06 #8
Pierre

Is it possible to use Lambda to make struct X generic?
aka.
typedef boost::function2<double, GENERIC_TYPE*, double> tFct;

so that I don't have to know the specification of struct X?

Regards
Lars Schouw

Jan 24 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Marian Aldenhövel | last post by:
Hi, I am using the FMOD audio-library with the pyFMOD python bindings. pyFMOD uses ctypes. It is possible to register callback functions with FMOD that are called at certain points in the...
3
by: ThinkRS232 | last post by:
I have a Win32 DLL that has a standard _stdcall (WINAPI) exports. I am able to call these fine from C#. One call in particular however has a callback to a CDECL function. How would I set that up?...
8
by: kurtcobain1978 | last post by:
-------------------------------------------------------------------------------- I need to do the exactly same thing in VB.NET. Load a unmanaged C DLL dynamically and then call a function in...
7
by: Kirk McDonald | last post by:
Let's say I have a function that takes a callback function as a parameter, and uses it to describe an iteration: def func(callback): for i in : callback(i) For the sake of argument, assume...
1
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <vector> using namespace System;
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
2
by: Pradeep | last post by:
Hi all, Can any one explain me what is callback function.... I have written some code after reading some tutorials from internet... But I am not sure is it a right way to write a call back...
6
by: jmDesktop | last post by:
In a function that takes another function (function pointer) as a argument, or the callback function, which is the one that "calls back"? I'm having a hard time understanding the language. Am I...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.