📄 csdn
字号:
<TABLE cellSpacing=1 cellPadding=0 width="100%" bgColor=#000000
border=0><TBODY>
<TR>
<TD vAlign=top bgColor=#ededed>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=right
background="CSDN技术中心 有没有试过将函数作为参数(parameter)来传递?(推荐).files/top.gif"
height=27><FONT
class=fonttitle>积极原创作者 </FONT></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=1 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/lynnboy">lynnboy</A> <FONT
color=#ff0000>(6)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/alcoholwang">alcoholwang</A> <FONT
color=#ff0000>(2)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/babyrockxray">babyrockxray</A> <FONT
color=#ff0000>(2)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/blueis">blueis</A> <FONT
color=#ff0000>(1)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/xiaopeng_e">xiaopeng_e</A> <FONT
color=#ff0000>(1)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/usersmj">usersmj</A> <FONT
color=#ff0000>(4)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/bpfish">bpfish</A> <FONT
color=#ff0000>(10)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/hongweijin">hongweijin</A> <FONT
color=#ff0000>(6)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/ljcao">ljcao</A> <FONT
color=#ff0000>(10)</FONT></TD></TR>
<TR>
<TD align=right><A
href="http://dev.csdn.net/user/scud">scud</A> <FONT
color=#ff0000>(6)</FONT></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top width=786>
<TABLE cellPadding=4 width="100%" border=0>
<TBODY>
<TR>
<TD width=10 height=19></TD>
<TD height=19>
<TABLE cellSpacing=3 cellPadding=3 width="100%" border=0>
<TBODY>
<TR>
<TD><A href="http://www.csdn.net/">CSDN</A> - <A
href="http://dev.csdn.net/">文档中心</A> - <FONT color=#003399><A
id=ArticleTitle1_ArticleTitle1_hlClass
href="http://dev.csdn.net/articlelist.aspx?c=1">Visual
C++</A></FONT> </TD>
<TD align=right>阅读:<SPAN
id=ArticleTitle1_ArticleTitle1_lblReadCount>947</SPAN>
评论: <SPAN
id=ArticleTitle1_ArticleTitle1_lblCommentCount>3</SPAN>
<A
href="http://dev.csdn.net/article/18/18162.shtm#Comment">参与评论</A>
</TD></TR></TBODY></TABLE>
<TABLE cellSpacing=3 cellPadding=3 width="100%" bgColor=#eeeeee
border=0>
<TBODY>
<TR>
<TD noWrap width=60 height=0></TD>
<TD></TD></TR>
<TR>
<TD noWrap align=middle bgColor=#003399 height=16><FONT
color=#ffffff>标题</FONT></TD>
<TD><B> <SPAN
id=ArticleTitle1_ArticleTitle1_lblTitle>有没有试过将函数作为参数(parameter)来传递?(推荐)</SPAN></B>
选择自 <A id=ArticleTitle1_ArticleTitle1_AuthorLink
href="http://dev.csdn.net/user/ilovenet">ilovenet</A> 的 Blog
</TD></TR>
<TR>
<TD align=middle bgColor=#003399 height=16><FONT
color=#ffffff>关键字</FONT></TD>
<TD width=500> <SPAN
id=ArticleTitle1_ArticleTitle1_lblKeywords>参数传递</SPAN></TD></TR>
<TR>
<TD align=middle bgColor=#003399 height=16><FONT
color=#ffffff>出处</FONT></TD>
<TD> <SPAN
id=ArticleTitle1_ArticleTitle1_lblSource></SPAN></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD width=10></TD>
<TD><SPAN id=ArticleContent1_ArticleContent1_lblContent>
<P>我们在传递函数的参数时,一般想到的都是一些诸如int,char,还有指针,引用之类</P>
<P>有没有想过将另外一个函数作为一个参数来传给调用函数呢?</P>
<P>也许这个功能比较少用,但真的很有效。</P>
<P>看看下面的例子</P>
<P>bool up(int a,int b) {return b<a;}
//两个简单的函数,执行着相反的功能<BR><BR>bool down(int a,int b) {return
b>a;}<BR><BR><BR><BR>void sort(int array[],const int size,bool
(*comp)(int,int))</P>
<P>//看清楚喽,上面是一个函数的指针<BR><BR>{<BR>。。。//你可以进行任意一个数组排序了<BR><BR>}<BR><BR><BR>然后,就可以这样调用了。 <BR></P><PRE><BR>sort(myintarray,myintarraysize,up);</PRE><PRE>想想,看有没有其它的用途,比如说代替头痛的递归呢。</PRE></SPAN><BR>
<DIV
style="FONT-SIZE: 14px; LINE-HEIGHT: 25px"><STRONG>作者Blog:</STRONG><A
id=ArticleContent1_ArticleContent1_AuthorBlogLink
href="http://blog.csdn.net/ilovenet/"
target=_blank>http://blog.csdn.net/ilovenet/</A></DIV>
<DIV
style="FONT-SIZE: 14px; COLOR: #900; LINE-HEIGHT: 25px"><STRONG>相关文章</STRONG></DIV>
<TABLE id=ArticleContent1_ArticleContent1_RelatedArticles
style="BORDER-COLLAPSE: collapse" cellSpacing=0 border=0>
<TBODY>
<TR>
<TD><A
href="http://dev.csdn.net/article/18/article/18/18164.shtm">如何在执行中暂停一个程序</A>
</TD></TR>
<TR>
<TD><A
href="http://dev.csdn.net/article/18/article/18/18162.shtm">有没有试过将函数作为参数(parameter)来传递?(推荐)</A>
</TD></TR>
<TR>
<TD><A
href="http://dev.csdn.net/article/18/article/18/18151.shtm">什么是名空间,为什么要使用它?</A>
</TD></TR>
<TR>
<TD><A
href="http://dev.csdn.net/article/18/article/18/18150.shtm">如何动态创建一个数组</A>
</TD></TR>
<TR>
<TD><A
href="http://dev.csdn.net/article/18/article/16/16939.shtm">windows
API简介--用户接口(系列2)</A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><A name=#Comment></A>
<TABLE cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center
bgColor=#006699 border=0>
<TBODY>
<TR bgColor=#006699>
<TD id=white align=middle width=556 bgColor=#006699><FONT
color=#ffffff>对该文的评论</FONT> </TD></TR></TBODY></TABLE>
<TABLE cellSpacing=1 cellPadding=2 width="100%" align=center
bgColor=#666666 border=0>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN
style="COLOR: #990000"><IMG height=16 hspace=1
src="CSDN技术中心 有没有试过将函数作为参数(parameter)来传递?(推荐).files/ico_pencil.gif"
width=16> </SPAN><SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl0_lblUserName>ynnwq</SPAN>
<I>( <SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl0_lblPostTime>2003-05-12</SPAN>)</I>
</TD></TR>
<TR>
<TD width=532 bgColor=#ffffff colSpan=3><SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl0_lblContent>虽然每本c/c++的书都有这个东西,不过,鼓励作者。。。<BR>其实,stl里很少用函数指针,而用的是函数对象,可能是比较oo吧,我也不大清楚。:)</SPAN>
</TD></TR></TBODY></TABLE>
<TABLE cellSpacing=1 cellPadding=2 width="100%" align=center
bgColor=#666666 border=0>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN
style="COLOR: #990000"><IMG height=16 hspace=1
src="CSDN技术中心 有没有试过将函数作为参数(parameter)来传递?(推荐).files/ico_pencil.gif"
width=16> </SPAN><SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl1_lblUserName>alittlefrag</SPAN>
<I>( <SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl1_lblPostTime>2003-05-06</SPAN>)</I>
</TD></TR>
<TR>
<TD width=532 bgColor=#ffffff colSpan=3><SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl1_lblContent>我用的jzip的源代码中,用到了一个回调函数,就是将函数指针作参数。实现进度显示,错误显示等功能。</SPAN>
</TD></TR></TBODY></TABLE>
<TABLE cellSpacing=1 cellPadding=2 width="100%" align=center
bgColor=#666666 border=0>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN
style="COLOR: #990000"><IMG height=16 hspace=1
src="CSDN技术中心 有没有试过将函数作为参数(parameter)来传递?(推荐).files/ico_pencil.gif"
width=16> </SPAN><SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl2_lblUserName>Tommy</SPAN>
<I>( <SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl2_lblPostTime>2003-05-03</SPAN>)</I>
</TD></TR>
<TR>
<TD width=532 bgColor=#ffffff colSpan=3><SPAN
id=CommnetList1_CommnetList1_rpCommentList__ctl2_lblContent>这个。。。好像随便找一本C语言的书上都有介绍的吧?平时虽然不是经常用,不过一个项目中总有机会用上一两次的吧</SPAN>
</TD></TR></TBODY></TABLE>
<DIV align=right><A id=CommnetList1_CommnetList1_Morelink
href="http://comment.csdn.net/Comment.aspx?c=2&s=18162">【评论】</A>
<A id=CommnetList1_CommnetList1_Hyperlink1
href="javascript:window.close();">【关闭】</A>
</DIV><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM><!-- 版权 -->
<HR align=center width=770 noShade SIZE=1>
<TABLE cellSpacing=0 cellPadding=0 width=500 align=center border=0>
<TBODY>
<TR>
<TD vAlign=bottom align=middle height=10><A
href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A
href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A
href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
height=48 src="CSDN技术中心 有没有试过将函数作为参数(parameter)来传递?(推荐).files/biaoshi.gif"
width=40 border=0></A></TD></TR>
<TR>
<TD vAlign=top align=middle>北京百联美达美数码科技有限公司 版权所有 京ICP证020026号</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.NET, Inc. All Rights
Reserved</FONT></TD></TR>
<TR>
<TD height=15></TD></TR></TBODY></TABLE><!-- /版权 -->
<SCRIPT>
document.write("<img src=http://count.csdn.net/count/pageview1.asp?columnid=4&itemid=11 border=0 width=0 height=0>");
</SCRIPT>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -