Article View: comp.lang.misc
Article #4282Re: c++ questions
From: John R Buchan (jatmon)
Date: Thu, 12 Oct 1995 05:50
Date: Thu, 12 Oct 1995 05:50
50 lines
1287 bytes
1287 bytes
In article <45htdt$qdv@duke.cs.duke.edu>, edwin@cs.duke.eduo says...
>
>I know I cannot pass function as a parameter.
>
>1. How can I pass a function as a parameter?
>e.g.
>
>void func1(){
>
>}
>
>void func2(void func1){
>
>}
>
>main()
>{
>
> func2(func1());
>
>
>}
The syntax and usage of function pointers is explained in the c.l.c faq,
which you can d/l by ftp from rtfm.mit.edu /pub/usenet/comp.lang.c.
#include <stdio.h>
void func1( void)
{
puts( "In func1.");
}
void func2(void (*fPtr)(void))
{
puts( "In func2, calling func1.");
fPtr();
puts( "Back in func2");
}
int main( void)
{
func2(func1);
return 0;
}
--
John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
Technical Details
Message-ID:
<45iaao$1kt@news.iag.net>Path:
arc1-ca.pugleaf.net!news.iag.net!usenetReferences:
<45htdt$qdv@duke.cs.duke.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.iag.net!usenet From: jatmon@iag.net (John R Buchan (jatmon)) Newsgroups: comp.lang.misc,comp.object,comp.lang.c++,comp.lang.c,comp.lang.object, Subject: Re: c++ questions Date: 12 Oct 1995 05:50:16 GMT Organization: Internet Access Group, Orlando, Florida Message-ID: <45iaao$1kt@news.iag.net> References: <45htdt$qdv@duke.cs.duke.edu> NNTP-Posting-Host: pm2-orl16.iag.net X-Newsreader: WinVN 0.99.6