| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sun Jan 29, 2006 12:00 am Post subject: question about function pointers |
|
|
I have an old fortran library which has a function f1 which expects a
function pointer to be passed to it of the type
double(*) (const double &)
I have a class Foo which has two functions
class Foo
{
public:
double f2 (const double &);
void f3 ();
};
| Quote: | From within f3(), I want to pass Foo::f2 as an argument to my Fortran
function f1. What is the cleanest way of doing this? Is mem_fun |
applicable in this case? |
|
| Back to top |
|
 |
Ben Radford Guest
|
Posted: Sun Jan 29, 2006 1:00 am Post subject: Re: question about function pointers |
|
|
amitmehrotra007 (AT) gmail (DOT) com wrote:
| Quote: | I have an old fortran library which has a function f1 which expects a
function pointer to be passed to it of the type
double(*) (const double &)
I have a class Foo which has two functions
class Foo
{
public:
double f2 (const double &);
void f3 ();
};
From within f3(), I want to pass Foo::f2 as an argument to my Fortran
function f1. What is the cleanest way of doing this? Is mem_fun
applicable in this case?
|
Since you are asking about mem_fun I assume you know that f2's type is
different from what f1 requires. Specifically double(Foo::*)(const
double&) instead of double(*)(const double&). I'm not an STL expert but
after a quick check of the mem_fun documentation I don't think it
applies to your case. It can be used as an adapter to call member
functions as if they were ordinary functions only when they have no
parameters.
--
Ben Radford
"Why is it drug addicts and computer aficionados are both called users?" |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Jan 29, 2006 3:00 am Post subject: Re: question about function pointers |
|
|
I think mem_fun can be used for member functions with no arguments or
one arguments. |
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Sun Jan 29, 2006 4:00 am Post subject: Re: question about function pointers |
|
|
* amitmehrotra007 (AT) gmail (DOT) com:
| Quote: | I have an old fortran library which has a function f1 which expects a
function pointer to be passed to it of the type
double(*) (const double &)
I have a class Foo which has two functions
class Foo
{
public:
double f2 (const double &);
void f3 ();
};
From within f3(), I want to pass Foo::f2 as an argument to my Fortran
function f1. What is the cleanest way of doing this?
|
Depends on whether you have to take threading into consideration or not.
If no threading, then
void f3()
{
static Foo* currentSelf;
struct Static
{
static double callback( double const& d )
{
return currentSelf->f2( d );
}
};
currentSelf = this; fortranFunc( &Static::callback );
}
| Quote: | Is mem_fun applicable in this case?
|
No, it produces a functor object, not a function.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? |
|
| Back to top |
|
 |
|