From: Ashutosh Ranjan <sigsegv@1net.gr>
To: elathan@phys.uoa.gr
Cc: "linux-c-programming@vger.kernel.org"
<linux-c-programming@vger.kernel.org>
Subject: Re: function pointers in C++
Date: 16 Mar 2004 00:40:37 +0530 [thread overview]
Message-ID: <1079377837.3584.4.camel@athlon.1.4.T.Bird> (raw)
In-Reply-To: <1079342899.405577335bb24@webmail.uoa.gr>
hi.
well check out mem_fun() which is standard library function...this takes
the pointer to a member function as its argument and produces something
that can be called for a pointer to the member's class.
Ex for your code...
taz(mem_function(&Foo::bar) should work...it should take the Foo*
argument and return what Foo::bar() returns !!
regards,
Ashu
On Mon, 2004-03-15 at 14:58, elathan@phys.uoa.gr wrote:
> Hello!
>
> Suppose I have:
>
> class Foo
> {
> public:
> Foo();
> ~Foo();
> int bar(int);
> };
>
> Now, why I can't do this:
>
> Foo *f = new Foo();
> taz(f->bar);
>
> Where taz()'s protype is:
>
> void taz(int (*f)(int));
>
> In plain C, I can do:
>
> int f(int) { ... }
> taz(f);
>
> without a problem. Is there a way to accomplish such a thing (i.e.
> to pass the pointer of a C++ class's member function to another
> function that expects a pointer to function as an argument)?
>
> Regards,
> --
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2004-03-15 19:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-15 9:28 function pointers in C++ 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 [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-03-15 14:21 Sandro Dangui
2004-03-15 11:28 ` Elias Athanasopoulos
2004-03-16 7:50 ` Glynn Clements
2004-03-18 11:17 ` Elias Athanasopoulos
2004-03-15 21:59 Sandro Dangui
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=1079377837.3584.4.camel@athlon.1.4.T.Bird \
--to=sigsegv@1net.gr \
--cc=elathan@phys.uoa.gr \
--cc=linux-c-programming@vger.kernel.org \
/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).