C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

question about function pointers

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sun Jan 29, 2006 12:00 am    Post subject: question about function pointers Reply with 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 ();
};

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





PostPosted: Sun Jan 29, 2006 1:00 am    Post subject: Re: question about function pointers Reply with quote



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






PostPosted: Sun Jan 29, 2006 3:00 am    Post subject: Re: question about function pointers Reply with quote



I think mem_fun can be used for member functions with no arguments or
one arguments.
Back to top
Alf P. Steinbach
Guest





PostPosted: Sun Jan 29, 2006 4:00 am    Post subject: Re: question about function pointers Reply with quote

* 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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.