473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 ();
};
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?

Jan 29 '06 #1
3 1529
am*************@gmail.com wrote:
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?"
Jan 29 '06 #2
I think mem_fun can be used for member functions with no arguments or
one arguments.

Jan 29 '06 #3
* am*************@gmail.com:
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 );
}

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?
Jan 29 '06 #4

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

Similar topics

4
by: Asif | last post by:
Hi there, I have been trying to understand the behaviour of char (*pfn)(null) for a couple of days. can some body help me understand the behaviour of char (*pfn)(null) in Visual C++ environment?...
62
by: ROSY | last post by:
hello experts plz answer following questions::: thanks in advance. 1. Out of fgets() and gets() which function is safe to use and why? 2. What is a far pointer? where we use it? 3. What does the...
18
by: steve | last post by:
I'm trying to create a structure of three pointers to doubles. For which I have: typedef struct { double *lst_t, *lst_vc, *lst_ic; } last_values; I then need to allocate space for...
9
by: Alfonso Morra | last post by:
Hi, I am having some probs with copying memory blocks around (part of a messaging library) and I would like some confirmation to make sure that I'm going about things the right way. I have...
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
14
by: streamkid | last post by:
i'm a learning newbie at c++... and i have the following question... reading some source code, i saw this: int function(const void * one, const void * two) { int var1, var2; var1 =...
4
by: Jeffrey Spoon | last post by:
Hello, I am trying to make a simple function that returns a pointer to another function. In my header file I've declared my function pointer: void (*pStateFunction) (void); //assume the function...
21
by: Chad | last post by:
At the following url http://c-faq.com/lib/qsort2.html, they have the following Q: Now I'm trying to sort an array of structures with qsort. My comparison function takes pointers to structures,...
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...
18
by: mdh | last post by:
May I ask the following. By K&R's own admission, the example used to describe function pointers is complex ( on P119). In addition, the use of casts has been stated by some on this group as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.