函数指针:
函数指针必须包含要调用的函数的内存地址,为了工作正确,指针还必须包含其他信息,即指针所指向的函数的参数列表中的参数类型以及返回类型。因此,在声明函数指针时,必须指定该指针可以指向的函数的参数类型和返回类型,以及指针名。
函数指针的一般形式如下:
返回类型(*指针明名)(参数类型列表);
注意:指针名上的括号是必不可少的,否则*就会与返回类型结合,就成了一个函数原型了。
示例:
#includeusing std::cout; using std::endl; //函数声明 long sum(long a,long b); long product(long a,long b); int main(int argc,char* argv[]){ //函数指针声明 long (*pfun)(long ,long)=0; //指向product函数 pfun=product; cout<
- <script type="text/java script">BAIDU_CLB_fillSlot("771048");
- 点击复制链接 与好友分享! 回本站首页 <script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];