做函数指针需要一个符号 [英] Do function pointers need an ampersand

查看:114
本文介绍了做函数指针需要一个符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C / C ++,如果我有以下功能:

In C/C++, if I have a the following functions:

void foo();
void bar(void (*funcPtr)());

有这两个调用之间的区别:

Is there a difference between these two calls:

bar(foo);
bar(&foo);

推荐答案

没有,没有任何区别,因为功能可以隐式转换为函数指针。
从标准的相关报价(N3376 4.3 / 1)。
<大段引用>


功能类型T的左值可以转换为类型指针到T一prvalue结果是一个指针
该功能。

No, there is no difference, since function can be implicitly converted to pointer to function. Relevant quote from standard (N3376 4.3/1).

An lvalue of function type T can be converted to a prvalue of type "pointer to T." The result is a pointer to the function.

这篇关于做函数指针需要一个符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆