From: Elias Athanasopoulos <elathan@phys.uoa.gr>
To: Sandro Dangui <sdangui@nortelnetworks.com>
Cc: linux-c-programming@vger.kernel.org, Dar?o Mariani <dmarian@fi.uba.ar>
Subject: Re: function pointers in C++
Date: Mon, 15 Mar 2004 13:28:49 +0200 [thread overview]
Message-ID: <20040315112849.GA774@velka.phys.uoa.gr> (raw)
In-Reply-To: <31E38B53D182D51195FA00508BE3A334036497A1@zwnbc004.cala.nortel.com>
On Mon, Mar 15, 2004 at 11:21:18AM -0300, Sandro Dangui wrote:
>
> I think this sample code will help you... Verify if it looks brilliant
> enough. :-))
Thanks for the detailed reply.
Actually, what I want to do is to pass a pointer to a member function in
a function that expects a pointer to function; I don't want to call the
member function, but just pass its address.
Following Stroustrup (pages 156..158), I did something like this:
Foo *f = new Foo(id);
double (Foo::*pfunc)(double *, double *) = &Foo::func;
Bar *res = new Bar((double (*)(double *, double *))(func->*pfunc));
And:
class Foo {
public:
Foo(int id);
~Foo();
double func(double *, double *);
};
Also Bar's constructor (I can't change it --third party implementation) is:
Bar(double (*)(double *, double *));
Amazingly I get the error:
test.cxx:107: error: converting from `double (Foo::*)(double*, double*)' to
`double (*)(double*, double*)'
which is *at least* annoying. It is another BIG suprise from C++. I mean,
there is, most probably, a good reason why this is not supported, but it is
a *broken design*.
Foo::func()'s prototype is (double) (double *, double *), which in my human
brain is compiled as: 'give me two pointers to double and I will give you one
double'. Why I can't pass it to a function which *expects* what my poor human brain
understands?
I didn't ask to convert for me a string to float...
Regards,
--
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky
next prev parent reply other threads:[~2004-03-15 11:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-15 14:21 function pointers in C++ Sandro Dangui
2004-03-15 11:28 ` Elias Athanasopoulos [this message]
2004-03-16 7:50 ` Glynn Clements
2004-03-18 11:17 ` Elias Athanasopoulos
-- strict thread matches above, loose matches on Subject: below --
2004-03-15 21:59 Sandro Dangui
2004-03-15 9:28 elathan
2004-03-15 10:27 ` Jan-Benedict Glaw
2004-03-15 10:39 ` elathan
2004-03-15 14:38 ` Darío Mariani
2004-03-15 14:56 ` Darío Mariani
2004-03-15 19:10 ` Ashutosh Ranjan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040315112849.GA774@velka.phys.uoa.gr \
--to=elathan@phys.uoa.gr \
--cc=dmarian@fi.uba.ar \
--cc=linux-c-programming@vger.kernel.org \
--cc=sdangui@nortelnetworks.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).